package com.seuic.hnapps.project;


import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.InputType;
import android.text.SpannableString;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectChangeListener;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.orhanobut.logger.Logger;
import com.seuic.hnapps.BaseActivity;
import com.seuic.hnapps.R;
import com.seuic.hnapps.adapter.Dq_adapter;
import com.seuic.hnapps.adapter.Select_subaccount_adapter;
import com.seuic.hnapps.bean.CardBinInfo_bean;
import com.seuic.hnapps.bean.DQ_Bean;
import com.seuic.hnapps.bean.Select_subaccount_Bean;
import com.seuic.hnapps.bean.StatisticalData_bean;
import com.seuic.hnapps.bean.Summary_Bean;
import com.seuic.hnapps.constants.EmvConstants;
import com.seuic.hnapps.posdsdk.pos_func.PosCallbacks;
import com.seuic.hnapps.posdsdk.pos_func.PosFuncs;
import com.seuic.hnapps.util.CZInterface;
import com.seuic.hnapps.util.CommAdapter;
import com.seuic.hnapps.util.Constants;
import com.seuic.hnapps.util.DateUtil;
import com.seuic.hnapps.util.LTFInterface;
import com.seuic.hnapps.util.PinPad;
import com.seuic.hnapps.util.PzGetUtils;
import com.seuic.hnapps.util.QBInterface;
import com.seuic.hnapps.util.SBAInterface;
import com.seuic.hnapps.util.ServiceCommon;
import com.seuic.hnapps.util.SpUtils;
import com.seuic.hnapps.util.THInterface;
import com.seuic.hnapps.util.TSFInterface;
import com.seuic.hnapps.util.Up_RundataUtils;
import com.seuic.hnapps.util.Utils;
import com.seuic.hnapps.util.VTAInterface;
import com.solab.enc.DES3;
import com.solab.enc.HexT;
import com.solab.enc.SMS4;
import com.solab.iso8583.IsoMessage;
import com.solab.iso8583.MessageFactory;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * isjingkai
 * 2019年7月20日10:47:53
 * 转账汇款
 */
public class RemittanceTransferActivity extends BaseActivity {
    //活期转定期标识
    private static final String TRANSITION_HZD = "HZD";
    //定期转活期标识
    private static final String TRANSITION_DZH = "DZH";
    @BindView(R.id.base_back_btn)
    LinearLayout baseBackBtn;
    @BindView(R.id.base_title_text)
    TextView baseTitleText;
    @BindView(R.id.rt_onesbank_btn)
    Button rtOnesbankBtn;
    @BindView(R.id.rt_otherbank_btn)
    Button rtOtherbankBtn;
    @BindView(R.id.rt_Transbetween_btn)
    Button rtTransbetweenBtn;
    @BindView(R.id.rt_maketype_layout)
    LinearLayout rtMaketypeLayout;
    //    @BindView(R.id.please_input_iccard_okbtn)
//    Button pleaseInputIccardOkbtn;
    @BindView(R.id.please_input_iccard_layout)
    LinearLayout pleaseInputIccardLayout;
    @BindView(R.id.inputnum_edtext)
    EditText inputnumEdtext;
    @BindView(R.id.input_gzbtn)
    Button inputGzbtn;
    @BindView(R.id.input_numokbtn)
    Button inputNumokbtn;
    @BindView(R.id.input_num_layout)
    LinearLayout inputNumLayout;
    @BindView(R.id.ficationing_layout)
    LinearLayout ficationingLayout;
    @BindView(R.id.input_money_edtext)
    EditText inputMoneyEdtext;
    @BindView(R.id.input_money_gzbtn)
    Button inputMoneyGzbtn;
    @BindView(R.id.input_money_okbtn)
    Button inputMoneyOkbtn;
    @BindView(R.id.input_money_layout)
    LinearLayout inputMoneyLayout;
    @BindView(R.id.real_time_btn)
    Button realTimeBtn;
    @BindView(R.id.next_day_btn)
    Button nextDayBtn;
    @BindView(R.id.common_btn)
    Button commonBtn;
    @BindView(R.id.select_waytozhang_layout)
    LinearLayout selectWaytozhangLayout;
    @BindView(R.id.sure_remittance_num)
    TextView sureRemittanceNum;
    @BindView(R.id.sure_remittance_money)
    TextView sureRemittanceMoney;
    @BindView(R.id.sure_remittance_name)
    TextView sureRemittanceName;
    @BindView(R.id.sure_remittance_type)
    TextView sureRemittanceType;
    @BindView(R.id.sure_remittance_gzbtn)
    Button sureRemittanceGzbtn;
    @BindView(R.id.sure_remittance_okbtn)
    Button sureRemittanceOkbtn;
    @BindView(R.id.dealing_layout)
    LinearLayout dealingLayout;
    @BindView(R.id.success_remittance_num)
    TextView successRemittanceNum;
    @BindView(R.id.success_remittance_money)
    TextView successRemittanceMoney;
    @BindView(R.id.success_remittance_name)
    TextView successRemittanceName;
    @BindView(R.id.success_remittance_type)
    TextView successRemittanceType;
    @BindView(R.id.success_remittance_gzbtn)
    Button successRemittanceGzbtn;
    @BindView(R.id.success_remittance_okbtn)
    Button successRemittanceOkbtn;
    @BindView(R.id.sure_printingpeper_okbtn)
    Button surePrintingpeperOkbtn;
    @BindView(R.id.sure_printingpeper_layout)
    LinearLayout surePrintingpeperLayout;
    @BindView(R.id.printing_layout)
    LinearLayout printingLayout;
    @BindView(R.id.sure_remittance_layout)
    LinearLayout sureRemittanceLayout;
    @BindView(R.id.success_remittance_layout)
    LinearLayout successRemittanceLayout;
    @BindView(R.id.show_selectbank_name)
    TextView showSelectbankName;
    @BindView(R.id.show_selectbank_btn)
    LinearLayout showSelectbankBtn;
    @BindView(R.id.show_selectbank_okbtn)
    Button showSelectbankOkbtn;
    @BindView(R.id.show_selectbank_layout)
    LinearLayout showSelectbankLayout;
    @BindView(R.id.bank_info_name)
    TextView bankInfoName;
    @BindView(R.id.bank_info_num)
    TextView bankInfoNum;
    @BindView(R.id.bank_info_okbtn)
    Button bankInfoOkbtn;
    @BindView(R.id.bank_info_layout)
    LinearLayout bankInfoLayout;
    @BindView(R.id.input_name_edtext)
    EditText inputNameEdtext;
    @BindView(R.id.input_name_gzbtn)
    Button inputNameGzbtn;
    @BindView(R.id.input_name_okbtn)
    Button inputNameOkbtn;
    @BindView(R.id.input_name_layout)
    LinearLayout inputNameLayout;
    @BindView(R.id.live_to_atfixedperiod_btn)
    Button liveToAtfixedperiodBtn;
    @BindView(R.id.atfixedperiod_to_live_btn)
    Button atfixedperiodToLiveBtn;
    @BindView(R.id.live_transfers_layout)
    LinearLayout liveTransfersLayout;
    @BindView(R.id.input_customanager_edtext)
    EditText inputCustomanagerEdtext;
    @BindView(R.id.input_customanager_gzbtn)
    Button inputCustomanagerGzbtn;
    @BindView(R.id.input_customanager_okbtn)
    Button inputCustomanagerOkbtn;
    @BindView(R.id.input_customanager_layout)
    LinearLayout inputCustomanagerLayout;
    @BindView(R.id.select_dealwholedeposit_btn)
    Button selectDealwholedepositBtn;
    @BindView(R.id.select_dealones_btn)
    Button selectDealonesBtn;
    @BindView(R.id.select_dealtype_layout)
    LinearLayout selectDealtypeLayout;
    @BindView(R.id.select_of_maturity_3mbtn)
    Button selectOfMaturity3mbtn;
    @BindView(R.id.select_of_maturity_6mbtn)
    Button selectOfMaturity6mbtn;
    @BindView(R.id.select_of_maturity_1ybtn)
    Button selectOfMaturity1ybtn;
    @BindView(R.id.select_of_maturity_2ybtn)
    Button selectOfMaturity2ybtn;
    @BindView(R.id.select_of_maturity_3ybtn)
    Button selectOfMaturity3ybtn;
    @BindView(R.id.select_of_maturity_5ybtn)
    Button selectOfMaturity5ybtn;
    @BindView(R.id.select_of_maturity_layout)
    LinearLayout selectOfMaturityLayout;
    @BindView(R.id.antomatic_conver_saving_nobtn)
    Button antomaticConverSavingNobtn;
    @BindView(R.id.antomatic_conver_saving_okbtn)
    Button antomaticConverSavingOkbtn;
    @BindView(R.id.antomatic_conver_saving_layout)
    LinearLayout antomaticConverSavingLayout;
    @BindView(R.id.sure_deal_info_title)
    TextView sureDealInfoTitle;
    @BindView(R.id.sure_deal_info_numtext)
    TextView sureDealInfoNumtext;
    @BindView(R.id.sure_deal_info_moneytext)
    TextView sureDealInfoMoneytext;
    @BindView(R.id.sure_deal_info_type)
    TextView sureDealInfoType;
    @BindView(R.id.sure_deal_info_nobtn)
    Button sureDealInfoNobtn;
    @BindView(R.id.sure_deal_info_okbtn)
    Button sureDealInfoOkbtn;
    @BindView(R.id.sure_deal_info_layout)
    LinearLayout sureDealInfoLayout;
    @BindView(R.id.home_card_layout)
    CardView homeCardLayout;
    @BindView(R.id.live_transfers_success_layout)
    CardView liveTransfersSuccessLayout;
    @BindView(R.id.live_transfers_success_usernum)
    TextView liveTransfersSuccessUsernum;
    @BindView(R.id.live_transfers_success_money)
    TextView liveTransfersSuccessMoney;
    @BindView(R.id.live_transfers_success_dealtype)
    TextView liveTransfersSuccessDealtype;
    @BindView(R.id.live_transfers_success_rateofinterest)
    TextView liveTransfersSuccessRateofinterest;
    @BindView(R.id.live_transfers_success_time)
    TextView liveTransfersSuccessTime;
    @BindView(R.id.live_transfers_success_isunloading)
    TextView liveTransfersSuccessIsunloading;
    @BindView(R.id.live_transfers_success_updata)
    TextView liveTransfersSuccessUpdata;
    @BindView(R.id.live_transfers_success_nobtn)
    Button liveTransfersSuccessNobtn;
    @BindView(R.id.live_transfers_success_okbtn)
    Button liveTransfersSuccessOkbtn;
    @BindView(R.id.select_subaccount_recyclerview)
    RecyclerView selectSubaccountRecyclerview;
    @BindView(R.id.select_subaccount_layout)
    CardView selectSubaccountLayout;
    @BindView(R.id.sure_switchinfo_layout)
    CardView sureSwitchinfoLayout;
    @BindView(R.id.sure_switchinfo_numtext)
    TextView sureSwitchinfoNumtext;
    @BindView(R.id.sure_switchinfo_moneytext)
    TextView sureSwitchinfoMoneytext;
    @BindView(R.id.sure_switchinfo_type)
    TextView sureSwitchinfoType;
    @BindView(R.id.sure_switchinfo_name)
    TextView sureSwitchinfoName;
    @BindView(R.id.sure_switchinfo_rate)
    TextView sureSwitchinfoRate;
    @BindView(R.id.sure_switchinfo_valuedate)
    TextView sureSwitchinfoValuedate;
    @BindView(R.id.sure_switchinfo_nobtn)
    Button sureSwitchinfoNobtn;
    @BindView(R.id.sure_switchinfo_yesbtn)
    Button sureSwitchinfoYesbtn;
    @BindView(R.id.switch_success_usernum)
    TextView switchSuccessUsernum;
    @BindView(R.id.switch_success_money)
    TextView switchSuccessMoney;
    @BindView(R.id.switch_success_dealtype)
    TextView switchSuccessDealtype;
    @BindView(R.id.switch_success_time)
    TextView switchSuccessTime;
    @BindView(R.id.switch_success_interest)
    TextView switchSuccessInterest;
    @BindView(R.id.switch_success_upday)
    TextView switchSuccessUpday;
    @BindView(R.id.switch_success_stopday)
    TextView switchSuccessStopday;
    @BindView(R.id.switch_success_nobtn)
    Button switchSuccessNobtn;
    @BindView(R.id.switch_success_okbtn)
    Button switchSuccessOkbtn;
    @BindView(R.id.switch_success_layout)
    CardView switchSuccessLayout;

    @BindView(R.id.input_bankname_edtext)
    EditText inputBanknameEdtext;
    @BindView(R.id.input_bankname_nobtn)
    Button inputBanknameNobtn;
    @BindView(R.id.input_bankname_okbtn)
    Button inputBanknameOkbtn;
    @BindView(R.id.input_bankname_layout)
    LinearLayout inputBanknameLayout;

    @BindView(R.id.select_1_btn)
    Button select1Btn;
    @BindView(R.id.select_7_btn)
    Button select7Btn;
    @BindView(R.id.select_cq_layout)
    LinearLayout selectCqLayout;
    @BindView(R.id.connected_to_no_btn)
    Button connectedToNoBtn;
    @BindView(R.id.connected_to_yes_btn)
    Button connectedToYesBtn;
    @BindView(R.id.connected_to_layout)
    LinearLayout connectedToLayout;
    @BindView(R.id.input_money_title)
    TextView inputMoneyTitle;


    //操作类型
    private String Transfer_type = "";
    Handler handler;
    Runnable runnable;
    private String shiftTo_name = "王惠农";
    private String account_type = "";
    private ArrayList<String> banks = new ArrayList<>();
    OptionsPickerView optionsPickerView;
    private static final String ONES = "ONES";
    //活转定 交易类型 text
    private String live_to_atfix = "";
    //活转定 存的时间
    private String save_time = "";
    //活转定 是否自动转存
    private String conver_saving = "";
    private PosFuncs posFuncs;
    //输入方式
    String input_type;
    //卡类型
    String CardType;
    //二磁信息
    String track2Data;
    //三磁信息
    String track3Data;
    //ic卡55信息
    String Field55;
    //银行卡号 读取 付款方
    String bindNum = "";
    //流水号
    private int num;
    //确认 输入账号 汇款方接收方out
    private String sureinput = "";
    //汇出方户名
    private String out_name;
    //汇入方户名
    private String in_name;

    private String password = "";
    //转账时间
    private String time;
    private String bank_type = "";
    //银行序号
    private String bind_num;
    //转出方机构号
    private String jgh;
    private String transition;
    private String select_cq;
    private List<Select_subaccount_Bean> Select_beans = new ArrayList<>();
    ;
    //position   recyclerview
    int positions;
    private String f122_3;
    private String f122_4;
    private String s_number;
    private String seqno;
    private String pdpname;
    private String depprd;
    private String trndintc;
    private String valdt;
    private String duedt;
    private String opacamt;
    private String lvs;
    private String qxr;
    private String dxr;
    private String ye;
    private String name;
    private String rwNUm;
    private String dqzh;
    private String qxr1;
    private String dxr1;
    private String cq;
    private String lx;
    private String pz_nums;
    private String a;
    private String b;

    int f59num = 0;
    String f59data = "";
    private Select_subaccount_adapter adapter;
    private boolean f59_dq;
    private String cz_num;
    private String cz_time;
    private String f39;
    private String run_time;
    private String f120type;


    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_remittance_transfer);
        ButterKnife.bind(this);
        this.setBackBtClick(R.id.base_back_btn);
        this.setTitleText(R.id.base_title_text, "(   " + "转账汇款" + "   )");
        posFuncs = PosFuncs.getInstace();
        posFuncs.init(this);
        initPackView();
        setPickViewData();
        nextDayBtn.setVisibility(View.GONE);
        commonBtn.setVisibility(View.GONE);
        showSelectbankName.setText("请选择银行");
        handler = new Handler();
    }

    @OnClick({R.id.rt_onesbank_btn, R.id.rt_otherbank_btn,
            R.id.rt_Transbetween_btn,
//            R.id.please_input_iccard_okbtn,
            R.id.input_gzbtn, R.id.input_numokbtn,
            R.id.input_money_gzbtn, R.id.input_money_okbtn,
            R.id.real_time_btn, R.id.next_day_btn,
            R.id.common_btn, R.id.sure_remittance_gzbtn,
            R.id.sure_remittance_okbtn, R.id.success_remittance_gzbtn,
            R.id.success_remittance_okbtn, R.id.sure_printingpeper_okbtn,
            R.id.show_selectbank_btn, R.id.show_selectbank_okbtn,
            R.id.bank_info_okbtn, R.id.input_name_gzbtn,
            R.id.input_name_okbtn, R.id.live_to_atfixedperiod_btn,
            R.id.atfixedperiod_to_live_btn, R.id.input_customanager_gzbtn,
            R.id.input_customanager_okbtn, R.id.select_dealwholedeposit_btn,
            R.id.select_dealones_btn, R.id.select_of_maturity_3mbtn,
            R.id.select_of_maturity_1ybtn, R.id.select_of_maturity_2ybtn,
            R.id.select_of_maturity_3ybtn, R.id.select_of_maturity_5ybtn,
            R.id.select_of_maturity_6mbtn, R.id.antomatic_conver_saving_nobtn,
            R.id.antomatic_conver_saving_okbtn, R.id.sure_deal_info_nobtn,
            R.id.sure_deal_info_okbtn, R.id.live_transfers_success_nobtn,
            R.id.live_transfers_success_okbtn, R.id.sure_switchinfo_nobtn,
            R.id.sure_switchinfo_yesbtn, R.id.switch_success_nobtn,
            R.id.switch_success_okbtn, R.id.input_bankname_nobtn, R.id.input_bankname_okbtn,
            R.id.select_1_btn, R.id.select_7_btn, R.id.connected_to_no_btn, R.id.connected_to_yes_btn
    })
    public void onViewClicked(final View view) {
        switch (view.getId()) {
            case R.id.rt_onesbank_btn:
                //转本行账户
                Transfer_type = "ones";
                rtMaketypeLayout.setVisibility(View.GONE);
                pleaseInputIccardLayout.setVisibility(View.VISIBLE);
                readCardTest();
                break;
            case R.id.rt_otherbank_btn:
                //转他行账户
//                Toast.makeText(this, "该功能尚未开通，敬请期待", Toast.LENGTH_SHORT).show();
                Transfer_type = "other";
                rtMaketypeLayout.setVisibility(View.GONE);
                pleaseInputIccardLayout.setVisibility(View.VISIBLE);
                readCardTest();
                break;
//            case R.id.please_input_iccard_okbtn:
//                //确定插入卡
//                pleaseInputIccardLayout.setVisibility(View.GONE);
//                ficationingLayout.setVisibility(View.VISIBLE);
//                runnable = new Runnable() {
//                    @Override
//                    public void run() {
//                        if (Transfer_type.equals("ones")) {
//                            ficationingLayout.setVisibility(View.GONE);
//                            inputNumLayout.setVisibility(View.VISIBLE);
//                        } else if (Transfer_type.equals("other")) {
//                            ficationingLayout.setVisibility(View.GONE);
//                            showSelectbankLayout.setVisibility(View.VISIBLE);
//                        }
//                    }
//                };
//                handler.postDelayed(runnable, 500);
//                break;
            case R.id.input_gzbtn:
                //输入汇款账号更正
                break;
            case R.id.input_numokbtn:
                //输入汇款账号确定
                if (inputnumEdtext.getText().toString().equals("")) {
                    Toast.makeText(this, "请输入汇款账号", Toast.LENGTH_SHORT).show();
                } else {
                    if (inputnumEdtext.getText().toString().length() > 20 || inputnumEdtext.getText().toString().length() < 15) {
                        Toast.makeText(this, "请输入正确的银行卡号", Toast.LENGTH_SHORT).show();
                    } else {
                        if (Transfer_type.equals("other")) {
                            //他行操作
                            inputNumLayout.setVisibility(View.GONE);
                            inputMoneyLayout.setVisibility(View.VISIBLE);
                        } else {
                            //本行操作
                            sureinput = "out";
                            inputNumLayout.setVisibility(View.GONE);
                            ficationingLayout.setVisibility(View.VISIBLE);
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                                    Logger.e("第一次获取rz" + num);
                                    excuteVTA(String.valueOf(num), inputnumEdtext.getText().toString(), "input", track2Data);
                                    SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                                    Logger.e("第二次获取rz" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0));
                                }
                            }).start();
                        }
                    }
                }
                break;
            case R.id.input_money_gzbtn:
                //输入金额更正
                inputMoneyEdtext.setText("");
                break;
            case R.id.input_money_okbtn:
                //输入金额确定

                if (inputMoneyEdtext.getText().toString().equals("")) {
                    Toast.makeText(this, "请输入取款金额", Toast.LENGTH_SHORT).show();
                } else {


                    if (inputMoneyEdtext.getText().toString().contains(".")) {
                        DecimalFormat df = new DecimalFormat("######0.00");
                        String mons[] = inputMoneyEdtext.getText().toString().split("\\.");
                        if (mons[1].length() > 2) {
                            Toast.makeText(this, "请输入正确的金额", Toast.LENGTH_SHORT).show();
                        } else {
                            inputMoneyOkbtn.setClickable(false);

                            Double d = Double.parseDouble(inputMoneyEdtext.getText().toString().trim());
                            df.format(d);
                            tradeWithCards(d * 100);
                        }
//                        enterPin(bindNum, d * 100);
                    } else {
                        inputMoneyOkbtn.setClickable(false);
                        tradeWithCards(Integer.parseInt(inputMoneyEdtext.getText().toString().trim()) * 100);
//                        enterPin(bindNum, Integer.parseInt(inputMoneyEdtext.getText().toString().trim()) * 100);
                    }
//                    if (Transfer_type == "transbetween") {
//
//                        enterPin(bindNum, Integer.parseInt(inputMoneyEdtext.getText().toString()) * 100);
//                    } else {
//                        enterPin(bindNum, Integer.parseInt(inputMoneyEdtext.getText().toString()) * 100);
//                    }
                }
                break;
            case R.id.real_time_btn:
                //实时到账
                account_type = "实时到账";
                selectWaytozhangLayout.setVisibility(View.GONE);
                sureRemittanceLayout.setVisibility(View.VISIBLE);

                if (Transfer_type == "other") {
                    sureRemittanceName.setText(inputNameEdtext.getText().toString());
                } else {
                    sureRemittanceName.setText(out_name);
                }
                sureRemittanceMoney.setText("￥" + inputMoneyEdtext.getText().toString());
                sureRemittanceNum.setText(inputnumEdtext.getText().toString());
                sureRemittanceType.setText("实时到账");

                break;
            case R.id.next_day_btn:
                //次日到账
                account_type = "次日到账";
                selectWaytozhangLayout.setVisibility(View.GONE);
                sureRemittanceLayout.setVisibility(View.VISIBLE);
                if (Transfer_type == "other") {
                    sureRemittanceName.setText(inputNameEdtext.getText().toString());
                } else {
                    sureRemittanceName.setText(out_name);
                }
                sureRemittanceMoney.setText("￥" + inputMoneyEdtext.getText().toString());
                sureRemittanceNum.setText(inputnumEdtext.getText().toString());
                sureRemittanceType.setText("次日到账");

                break;
            case R.id.common_btn:
                //普通到账
                account_type = "普通到账";
                selectWaytozhangLayout.setVisibility(View.GONE);
                sureRemittanceLayout.setVisibility(View.VISIBLE);
                if (Transfer_type == "other") {
                    sureRemittanceName.setText(inputNameEdtext.getText().toString());
                } else {
                    sureRemittanceName.setText(out_name);
                }
                sureRemittanceMoney.setText("￥" + inputMoneyEdtext.getText().toString());
                sureRemittanceNum.setText(inputnumEdtext.getText().toString());
                sureRemittanceType.setText("普通到账");

                break;
            case R.id.sure_remittance_gzbtn:
                //确认转账 取消
                this.finish();
                break;
            case R.id.sure_remittance_okbtn:
                //确认转账 确认
                sureRemittanceLayout.setVisibility(View.GONE);
                dealingLayout.setVisibility(View.VISIBLE);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");// HH:mm:ss
                        //获取当前时间
                        Date date = new Date(System.currentTimeMillis());
                        time = simpleDateFormat.format(date);

                        run_time = DateUtil.getCurrentTime(DateUtil.M_TIME_PATTERN);
                        if (Transfer_type.equals("other")) {
                            num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                            Logger.e("第一次获取rz" + num);
                            enterTH(String.valueOf(num));

                            SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                            Logger.e("第二次获取rz" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0));

                        } else {

                            cz_time = time;

                            run_time = DateUtil.getCurrentTime(DateUtil.M_TIME_PATTERN);
                            num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                            cz_num = String.valueOf(num);
                            SpUtils.getSPUtil(getApplicationContext()).putString("cz_Num", cz_num);
                            SpUtils.getSPUtil(getApplicationContext()).putString("cz_time", cz_time);
                            SpUtils.getSPUtil(getApplicationContext()).putString("cz_money", inputMoneyEdtext.getText().toString());
                            SpUtils.getSPUtil(getApplicationContext()).putString("injon_bind", inputnumEdtext.getText().toString());

                            Logger.e("第一次获取rz" + num);

                            enterTSF(String.valueOf(num), time);

                            SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                            Logger.e("第二次获取rz" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0));

                        }


                    }
                }).start();

                break;
            case R.id.success_remittance_gzbtn:
                //转账成功 取消
                this.finish();
                break;
            case R.id.success_remittance_okbtn:
                //转账成功 确认
                successRemittanceLayout.setVisibility(View.GONE);

                surePrintingpeperLayout.setVisibility(View.VISIBLE);


                break;
            case R.id.sure_printingpeper_okbtn:
                //打印纸安装 确认
                surePrintingpeperLayout.setVisibility(View.GONE);
                printingLayout.setVisibility(View.VISIBLE);
                if (Transfer_type.equals("ones") || Transfer_type.equals("other")) {
                    paint();
                } else if (transition == TRANSITION_DZH) {
                    dzhPaint();
                } else if (transition == TRANSITION_HZD) {
                    hzdPaint();
                }
                break;
            case R.id.show_selectbank_btn:
                //选择银行
                optionsPickerView.show();
                break;
            case R.id.show_selectbank_okbtn:
                //确定银行
                if (bank_type.equals("")) {
                    Toast.makeText(this, "请选择银行", Toast.LENGTH_SHORT).show();
                } else {
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                            Logger.e("第一次获取rz" + num + CardType);
                            excuteQB(String.valueOf(num));
                            SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                            Logger.e("第二次获取rz" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0));
                        }
                    }).start();
                }
                break;
            case R.id.bank_info_okbtn:
                //确认银行信息
                bankInfoLayout.setVisibility(View.GONE);
                inputNameLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.input_name_gzbtn:
                //转入人姓名 更正
                inputNameEdtext.setText("");
                break;
            case R.id.input_name_okbtn:
                //转入人姓名 确定
                if (inputNameEdtext.getText().toString().equals("")) {
                    Toast.makeText(this, "请输入转入人姓名", Toast.LENGTH_SHORT).show();
                } else {
                    inputNameLayout.setVisibility(View.GONE);
                    inputNumLayout.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.rt_Transbetween_btn:
                //定活互转
                Transfer_type = "transbetween";
                inputMoneyEdtext.setInputType(InputType.TYPE_CLASS_NUMBER);
                rtMaketypeLayout.setVisibility(View.GONE);
                liveTransfersLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.live_to_atfixedperiod_btn:
                //活期转定期
                transition = TRANSITION_HZD;
                inputMoneyTitle.setText("转入金额");
                SpannableString s = new SpannableString("请输入转入金额");//这里输入自己想要的提示文字
                inputMoneyEdtext.setHint(s);
                liveTransfersLayout.setVisibility(View.GONE);
                pleaseInputIccardLayout.setVisibility(View.VISIBLE);
                readCardTest();
                break;
            case R.id.atfixedperiod_to_live_btn:
                //定期转活期
                transition = TRANSITION_DZH;
                liveTransfersLayout.setVisibility(View.GONE);
                pleaseInputIccardLayout.setVisibility(View.VISIBLE);
                tradeWithCards(0);
                break;
            case R.id.input_customanager_gzbtn:
                //输入客户经理号 更正
                inputCustomanagerEdtext.setText("");
                break;
            case R.id.input_customanager_okbtn:
                //输入客户经理号 确定
                if (inputCustomanagerEdtext.getText().toString().equals("")) {
                    Toast.makeText(this, "请输入客户经理号", Toast.LENGTH_SHORT).show();

                } else if (inputCustomanagerEdtext.getText().toString().length() != 7) {
                    Toast.makeText(this, "请输入正确的客户经理号", Toast.LENGTH_SHORT).show();
                } else {
                    inputCustomanagerLayout.setVisibility(View.GONE);
                    selectDealtypeLayout.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.select_dealwholedeposit_btn:
                //整存整取
                selectDealtypeLayout.setVisibility(View.GONE);
                live_to_atfix = "整存整取";
                selectOfMaturityLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.select_dealones_btn:
                //个人通知取款
                selectDealtypeLayout.setVisibility(View.GONE);
                live_to_atfix = "个人通知取款";
                selectCqLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.select_of_maturity_3mbtn:
                // 存期3个月
                save_time = "三个月";
                selectOfMaturityLayout.setVisibility(View.GONE);
                antomaticConverSavingLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.select_of_maturity_6mbtn:
                // 存期6个月
                save_time = "六个月";
                selectOfMaturityLayout.setVisibility(View.GONE);
                antomaticConverSavingLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.select_of_maturity_1ybtn:
                // 存期1年
                save_time = "一年";
                selectOfMaturityLayout.setVisibility(View.GONE);
                antomaticConverSavingLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.select_of_maturity_2ybtn:
                // 存期2年
                save_time = "两年";
                selectOfMaturityLayout.setVisibility(View.GONE);
                antomaticConverSavingLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.select_of_maturity_3ybtn:
                // 存期3年
                save_time = "三年";
                selectOfMaturityLayout.setVisibility(View.GONE);
                antomaticConverSavingLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.select_of_maturity_5ybtn:
                // 存期5年
                save_time = "五年";
                selectOfMaturityLayout.setVisibility(View.GONE);
                antomaticConverSavingLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.antomatic_conver_saving_nobtn:
                //自动转存 否
                conver_saving = "否";
                antomaticConverSavingLayout.setVisibility(View.GONE);
                inputMoneyLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.antomatic_conver_saving_okbtn:
                //自动转存 是
                conver_saving = "是";
                antomaticConverSavingLayout.setVisibility(View.GONE);
                inputMoneyLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.sure_deal_info_nobtn:
                //确认转换信息 取消
                this.finish();
                break;
            case R.id.sure_deal_info_okbtn:
                //确认转换信息 确定
                sureDealInfoLayout.setVisibility(View.GONE);
                dealingLayout.setVisibility(View.VISIBLE);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        run_time = DateUtil.getCurrentTime(DateUtil.M_TIME_PATTERN);


                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");// HH:mm:ss
                        //获取当前时间
                        Date date = new Date(System.currentTimeMillis());
                        time = simpleDateFormat.format(date);
                        num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                        Logger.e("第一次获取rz" + num + CardType);
                        enterLTF(String.valueOf(num));
                        SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                        Logger.e("第二次获取rz" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0));
                    }
                }).start();
                break;
            case R.id.live_transfers_success_nobtn:
                //活转定转账成功 取消
                this.finish();
                break;
            case R.id.live_transfers_success_okbtn:
                //活转定转账成功  确定
                liveTransfersSuccessLayout.setVisibility(View.GONE);
                homeCardLayout.setVisibility(View.VISIBLE);
                dealingLayout.setVisibility(View.GONE);
                surePrintingpeperLayout.setVisibility(View.VISIBLE);

                break;
            case R.id.sure_switchinfo_nobtn:
                //确认转换信息  取消
                this.finish();
                break;
            case R.id.sure_switchinfo_yesbtn:
                //确认转换信息 确认
                sureSwitchinfoLayout.setVisibility(View.GONE);
                homeCardLayout.setVisibility(View.VISIBLE);
                dealingLayout.setVisibility(View.VISIBLE);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        run_time = DateUtil.getCurrentTime(DateUtil.M_TIME_PATTERN);

                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");// HH:mm:ss
                        //获取当前时间
                        Date date = new Date(System.currentTimeMillis());
                        time = simpleDateFormat.format(date);
                        num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                        Logger.e("第一次获取rz" + num + CardType);
                        enterDZH(String.valueOf(num));
                        SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                        Logger.e("第二次获取rz" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0));
                    }
                }).start();

                break;
            case R.id.switch_success_nobtn:
                //定转活 交易成功 取消
                this.finish();
                break;
            case R.id.switch_success_okbtn:
                //定转活 交易成功 确定
                liveTransfersSuccessLayout.setVisibility(View.GONE);
                homeCardLayout.setVisibility(View.VISIBLE);
                dealingLayout.setVisibility(View.GONE);
                surePrintingpeperLayout.setVisibility(View.VISIBLE);
                switchSuccessLayout.setVisibility(View.GONE);
                break;
            case R.id.input_bankname_nobtn:
                //输入银行名更正
                inputBanknameEdtext.setText("");
                break;
            case R.id.input_bankname_okbtn:
                //输入银行名确定
                if (inputBanknameEdtext.getText().toString().equals("")) {
                    Toast.makeText(this, "请输入银行名称", Toast.LENGTH_SHORT).show();
                } else {
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                            Logger.e("第一次获取rz" + num + CardType);
                            excuteQB(String.valueOf(num));
                            SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                            Logger.e("第二次获取rz" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0));
                        }
                    }).start();
                }
                break;
            case R.id.select_1_btn:
                //个人通知存款 1天
                select_cq = "1";
                selectCqLayout.setVisibility(View.GONE);
//                antomaticConverSavingLayout.setVisibility(View.VISIBLE);
                conver_saving = "否";
                inputMoneyLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.select_7_btn:
                //个人通知存款 7天
                select_cq = "7";
                selectCqLayout.setVisibility(View.GONE);
//                antomaticConverSavingLayout.setVisibility(View.VISIBLE);
                conver_saving = "否";
                inputMoneyLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.connected_to_no_btn:
                //取消联网检查

                break;
            case R.id.connected_to_yes_btn:
                //确定联网检查


                homeCardLayout.setVisibility(View.GONE);
                sureSwitchinfoNumtext.setText(bindNum);
                sureSwitchinfoName.setText(Select_beans.get(positions).getName() + "");
                sureSwitchinfoMoneytext.setText(Select_beans.get(positions).getBalanceofAccount());
                sureSwitchinfoRate.setText(Select_beans.get(positions).getRateofinterest());
                sureSwitchinfoValuedate.setText(Select_beans.get(positions).getValuedate());
                sureSwitchinfoType.setText("定期转活期");
                sureSwitchinfoLayout.setVisibility(View.VISIBLE);


                break;

        }
    }


//    private void initRecyclerView() {
//        List<Select_subaccount_Bean> beans = new ArrayList<>();
//        Select_subaccount_Bean bean = new Select_subaccount_Bean("三个月整存整储蓄存款", 00001, 100000, "2019.7.29", "1年", "3%");
//        Select_subaccount_Bean bean1 = new Select_subaccount_Bean("三个月整存整储蓄存款", 00001, 100000, "2019.7.29", "1年", "3%");
//        Select_subaccount_Bean bean2 = new Select_subaccount_Bean("三个月整存整储蓄存款", 00001, 100000, "2019.7.29", "1年", "3%");
//
//        beans.add(bean);
//        beans.add(bean1);
//        beans.add(bean2);
//
//        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
//        selectSubaccountRecyclerview.setLayoutManager(linearLayoutManager);
//        Select_subaccount_adapter adapter = new Select_subaccount_adapter(R.layout.select_subaccount_adapter_item_layout, beans, "");
//        selectSubaccountRecyclerview.setAdapter(adapter);
//        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
//            @Override
//            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
//                Toast.makeText(RemittanceTransferActivity.this, "aaaaa", Toast.LENGTH_SHORT).show();
//                selectSubaccountLayout.setVisibility(View.GONE);
//
//                sureSwitchinfoNumtext.setText("11111111");
//                sureSwitchinfoName.setText("三个月整整储蓄贷款");
//                sureSwitchinfoMoneytext.setText("￥1000.00");
//                sureSwitchinfoType.setText("定期转活期");
//                sureSwitchinfoRate.setText("1.54%");
//                sureSwitchinfoValuedate.setText("2019.7.29");
//                sureSwitchinfoLayout.setVisibility(View.VISIBLE);
//            }
//        });
//
//    }

    private void initPackView() {
        optionsPickerView = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                bank_type = (banks.get(options1));
                Toast.makeText(RemittanceTransferActivity.this, banks.get(options1), Toast.LENGTH_SHORT).show();
                showSelectbankName.setText(banks.get(options1));
                if (bank_type.equals("其他")) {
                    showSelectbankLayout.setVisibility(View.GONE);
                    inputBanknameLayout.setVisibility(View.VISIBLE);
                }
            }
        }).setOptionsSelectChangeListener(new OnOptionsSelectChangeListener() {
            @Override
            public void onOptionsSelectChanged(int options1, int options2, int options3) {
            }
        })
                .setSelectOptions(0)
                .build();
        optionsPickerView.setPicker(banks);
    }

    private void setPickViewData() {
        banks.add("中国工商银行");
        banks.add("中国农业银行");
        banks.add("中国银行");
        banks.add("中国建设银行");
        banks.add("交通银行");
        banks.add("招商银行");
        banks.add("其他");
    }

    /**
     * 定转活打印
     */
    private void dzhPaint() {
        new Thread() {
            @Override
            public void run() {
                super.run();
                posFuncs.printerClearBuffer();
                posFuncs.printerAppendLargeTextAlignCenter("烟台银行 通用凭证");

                posFuncs.printerAppendTextline("交易时间 :" + time);
                posFuncs.printerAppendTextline("设备号 :" + Constants.YANTAI_TERMNO);
                posFuncs.printerAppendTextline("操作员 :" + SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""));
                posFuncs.printerAppendTextline("转出账号 :" + bindNum);

                posFuncs.printerAppendTextline("流水号 :" + rwNUm);

                posFuncs.printerAppendTextline("业务类型 :定期转活期");
                posFuncs.printerAppendTextline("户名 :" + name);

                posFuncs.printerAppendTextline("金额 :" + Select_beans.get(positions).getBalanceofAccount() + ".00");
                posFuncs.printerAppendTextline("定期子号 :" + Select_beans.get(positions).getNum());
                posFuncs.printerAppendTextline("存款种类 :" + Select_beans.get(positions).getName());
//                posFuncs.printerAppendTextline("存期 :" + cq + "天");
                posFuncs.printerAppendTextline("利息 :" + lx);
                posFuncs.printerAppendTextline("起息日 :" + Select_beans.get(positions).getValuedate());
                if (Select_beans.get(positions).getName().equals("一天个人通知存款") || Select_beans.get(positions).getName().equals("七天个人通知存款")) {
                    posFuncs.printerAppendTextline("到期日 :");
                } else {
                    posFuncs.printerAppendTextline("到期日 :" + Select_beans.get(positions).getDuedate());
                }
//                posFuncs.printerAppendTextline("本息合计 :");
                posFuncs.printerAppendTextline("凭证序号 :" + pz_nums);
                posFuncs.printerAppendTextline("客户签字确认 :");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("--------------------------------------");
                posFuncs.printerAppendLargeTextAlignCenter("烟台银行 通用凭证");
                posFuncs.printerAppendTextline("交易时间 :" + time);
                posFuncs.printerAppendTextline("设备号 :" + Constants.YANTAI_TERMNO);
                posFuncs.printerAppendTextline("操作员 :" + SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""));
                String bindx = bindNum.substring(6, bindNum.length() - 5);
                String bindxs = "*";
                for (int i = 0; i < bindx.length(); i++) {
                    bindxs = bindxs + "*";
                }
                posFuncs.printerAppendTextline("转出账号 :" + bindNum.substring(0, 6) + bindxs + bindNum.substring(bindNum.length() - 4, bindNum.length()));

                posFuncs.printerAppendTextline("流水号 :" + rwNUm);

                posFuncs.printerAppendTextline("业务类型 :定期转活期");
                String RemittanceNameone = name.substring(0, 1);
                posFuncs.printerAppendTextline("户名 :" + name.replaceFirst(RemittanceNameone, "*"));


                posFuncs.printerAppendTextline("金额 :" + Select_beans.get(positions).getBalanceofAccount() + ".00");
                posFuncs.printerAppendTextline("定期子号 :" + Select_beans.get(positions).getNum());
                posFuncs.printerAppendTextline("存款种类 :" + Select_beans.get(positions).getName());
//                posFuncs.printerAppendTextline("存期 :" + cq + "天");
                posFuncs.printerAppendTextline("利息 :" + lx);
                posFuncs.printerAppendTextline("起息日 :" + Select_beans.get(positions).getValuedate());
                if (Select_beans.get(positions).getName().equals("一天个人通知存款") || Select_beans.get(positions).getName().equals("七天个人通知存款")) {
                    posFuncs.printerAppendTextline("到期日 :");
                } else {
                    posFuncs.printerAppendTextline("到期日 :" + Select_beans.get(positions).getDuedate());
                }

//                posFuncs.printerAppendTextline("本息合计 :");
                posFuncs.printerAppendTextline("凭证序号 :" + pz_nums);
                posFuncs.printerAppendTextline("客户签字确认 :");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");


                posFuncs.startPrint(new PosCallbacks.PrintCallbacaks() {
                    @Override
                    public void onSuccess() {
                        Toast.makeText(RemittanceTransferActivity.this, "打印成功", Toast.LENGTH_SHORT).show();
                        finish();
                    }

                    @Override
                    public void onFailed(String error) {
                        if (error.equals("Lack Paper")) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(RemittanceTransferActivity.this, "请确认打印纸安装正确", Toast.LENGTH_SHORT).show();
                                    surePrintingpeperLayout.setVisibility(View.VISIBLE);
                                    printingLayout.setVisibility(View.GONE);
                                }
                            });
                        }
                    }
                });
            }
        }.start();
    }

    /**
     * 活转定打印
     */
    private void hzdPaint() {
        new Thread() {
            @Override
            public void run() {
                super.run();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");// HH:mm:ss
                //获取当前时间
                Date date = new Date(System.currentTimeMillis());
                posFuncs.printerClearBuffer();
                posFuncs.printerAppendLargeTextAlignCenter("烟台银行 通用凭证");
                posFuncs.printerAppendTextline("交易时间 :" + time);
                posFuncs.printerAppendTextline("设备号 :" + Constants.YANTAI_TERMNO);
                posFuncs.printerAppendTextline("操作员 :" + SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""));
                posFuncs.printerAppendTextline("转出账号 :" + bindNum);

                posFuncs.printerAppendTextline("流水号 :" + rwNUm);

                posFuncs.printerAppendTextline("业务类型 :活期转定期");
                posFuncs.printerAppendTextline("户名 :" + name.substring(0, 5));
                a = ye.replaceFirst("^0+", "").substring(0, ye.replaceFirst("^0+", "").length() - 2);
                b = ye.replaceFirst("^0+", "").substring(ye.replaceFirst("^0+", "").length() - 2);
                posFuncs.printerAppendTextline("金额 :" + a + "." + b);
                posFuncs.printerAppendTextline("定期子号 :" + dqzh);
                posFuncs.printerAppendTextline("存款种类 :" + live_to_atfix);

                if (live_to_atfix == "个人通知取款") {
                    if (select_cq == "1") {
                        posFuncs.printerAppendTextline("存期 :" + "一天");
                    } else {
                        posFuncs.printerAppendTextline("存期 :" + "七天");
                    }

                } else {
                    posFuncs.printerAppendTextline("存期 :" + save_time);
                }
                posFuncs.printerAppendTextline("自动转存 :" + conver_saving);

                posFuncs.printerAppendTextline("起息日 :" + simpleDateFormat.format(date).replace("/", ""));
                if (live_to_atfix == "个人通知取款") {
                    posFuncs.printerAppendTextline("到期日 :");
                } else {
                    posFuncs.printerAppendTextline("到期日 :" + dxr);
                }

                posFuncs.printerAppendTextline("利率 :" + lvs);
                posFuncs.printerAppendTextline("凭证序号 :" + pz_nums);
                posFuncs.printerAppendTextline("客户签字确认 :");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("--------------------------------------");
                posFuncs.printerAppendLargeTextAlignCenter("烟台银行 通用凭证");
                posFuncs.printerAppendTextline("交易时间 :" + time);
                posFuncs.printerAppendTextline("设备号 :" + Constants.YANTAI_TERMNO);
                posFuncs.printerAppendTextline("操作员 :" + SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""));
                String bindx = bindNum.substring(6, bindNum.length() - 5);
                String bindxs = "*";
                for (int i = 0; i < bindx.length(); i++) {
                    bindxs = bindxs + "*";
                }
                posFuncs.printerAppendTextline("转出账号 :" + bindNum.substring(0, 6) + bindxs + bindNum.substring(bindNum.length() - 4, bindNum.length()));

                posFuncs.printerAppendTextline("流水号 :" + rwNUm);

                posFuncs.printerAppendTextline("业务类型 :活期转定期");
                String RemittanceNameone = name.substring(0, 1);
                posFuncs.printerAppendTextline("户名 :" + name.replaceFirst(RemittanceNameone, "*"));
                posFuncs.printerAppendTextline("金额 :" + a + "." + b);
                posFuncs.printerAppendTextline("定期子号 :" + dqzh);
                posFuncs.printerAppendTextline("存款种类 :" + live_to_atfix);
                if (live_to_atfix == "个人通知取款") {
                    if (select_cq == "1") {
                        posFuncs.printerAppendTextline("存期 :" + "一天");

                    } else {
                        posFuncs.printerAppendTextline("存期 :" + "七天");
                    }

                } else {
                    posFuncs.printerAppendTextline("存期 :" + save_time);
                }

                posFuncs.printerAppendTextline("自动转存 :" + conver_saving);
                posFuncs.printerAppendTextline("起息日 :" + simpleDateFormat.format(date).replace("/", ""));
                if (live_to_atfix == "个人通知取款") {
                    posFuncs.printerAppendTextline("到期日 :");
                } else {
                    posFuncs.printerAppendTextline("到期日 :" + dxr);
                }
                posFuncs.printerAppendTextline("利率 :" + lvs);
                posFuncs.printerAppendTextline("凭证序号 :" + pz_nums);
                posFuncs.printerAppendTextline("客户签字确认 :");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");


                posFuncs.startPrint(new PosCallbacks.PrintCallbacaks() {
                    @Override
                    public void onSuccess() {
                        Toast.makeText(RemittanceTransferActivity.this, "打印成功", Toast.LENGTH_SHORT).show();
                        finish();
                    }

                    @Override
                    public void onFailed(String error) {
                        if (error.equals("Lack Paper")) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(RemittanceTransferActivity.this, "请确认打印纸安装正确", Toast.LENGTH_SHORT).show();
                                    surePrintingpeperLayout.setVisibility(View.VISIBLE);
                                    printingLayout.setVisibility(View.GONE);
                                }
                            });
                        }
                    }
                });
            }
        }.start();
    }

//    /**
//     * 活转定打印
//     */
//    private void hzdPaint() {
//        new Thread() {
//            @Override
//            public void run() {
//                super.run();
//                posFuncs.printerClearBuffer();
//                posFuncs.printerAppendLargeTextAlignCenter("烟台银行");
//                posFuncs.printerAppendLargeTextAlignCenter("通用凭证");
//                posFuncs.printerAppendTextline("交易时间 :" + time);
//                posFuncs.printerAppendTextline("设备号 :" + Constants.YANTAI_TERMNO);
//                posFuncs.printerAppendTextline("操作员 :");
//                posFuncs.printerAppendTextline("转出账号 :" + bindNum);
//
//                posFuncs.printerAppendTextline("流水号 :");
//
//                posFuncs.printerAppendTextline("业务类型 :活期转定期");
//                posFuncs.printerAppendTextline("户名 :"+name);
//
//                posFuncs.printerAppendTextline("余额 :" + ye);
//                posFuncs.printerAppendTextline("定期字号 :");
//                posFuncs.printerAppendTextline("存款种类 :" + live_to_atfix);
//                posFuncs.printerAppendTextline("存期 :" + save_time);
//                posFuncs.printerAppendTextline("自动转存 :" + conver_saving);
//                posFuncs.printerAppendTextline("起息日 :" + qxr);
//                posFuncs.printerAppendTextline("到息日 :" + dxr);
//                posFuncs.printerAppendTextline("利率 :" + lvs);
//                posFuncs.printerAppendTextline("凭证序号 :" + num);
//                posFuncs.printerAppendTextline("客户签字确认 :");
//                posFuncs.printerAppendTextline("");
//                posFuncs.printerAppendTextline("");
//                posFuncs.printerAppendTextline("--------------------------------------");
//                posFuncs.printerAppendTextline("交易时间 :" + time);
//                posFuncs.printerAppendTextline("设备号 :" + Constants.YANTAI_TERMNO);
//                posFuncs.printerAppendTextline("操作员 :");
//                posFuncs.printerAppendTextline("转出账号 :" + bindNum);
//
//                posFuncs.printerAppendTextline("流水号 :");
//
//                posFuncs.printerAppendTextline("业务类型 :活期转定期");
//                posFuncs.printerAppendTextline("户名 :"+name);
//
//                posFuncs.printerAppendTextline("余额 :" + ye);
//                posFuncs.printerAppendTextline("定期字号 :");
//                posFuncs.printerAppendTextline("存款种类 :" + live_to_atfix);
//                posFuncs.printerAppendTextline("存期 :" + save_time);
//                posFuncs.printerAppendTextline("自动转存 :" + conver_saving);
//                posFuncs.printerAppendTextline("起息日 :" + qxr);
//                posFuncs.printerAppendTextline("到息日 :" + dxr);
//                posFuncs.printerAppendTextline("利率 :" + lvs);
//                posFuncs.printerAppendTextline("凭证序号 :" + num);
//                posFuncs.printerAppendTextline("客户签字确认 :");
//                posFuncs.printerAppendTextline("");
//                posFuncs.printerAppendTextline("");
//                posFuncs.printerAppendTextline("");
//                posFuncs.printerAppendTextline("");
//                posFuncs.printerAppendTextline("");
//                posFuncs.printerAppendTextline("");
//                posFuncs.printerAppendTextline("");
//
//
//                posFuncs.startPrint(new PosCallbacks.PrintCallbacaks() {
//                    @Override
//                    public void onSuccess() {
//                        Toast.makeText(RemittanceTransferActivity.this, "打印成功", Toast.LENGTH_SHORT).show();
//                        finish();
//                    }
//
//                    @Override
//                    public void onFailed(String error) {
//                        if (error.equals("Lack Paper")) {
//                            runOnUiThread(new Runnable() {
//                                @Override
//                                public void run() {
//                                    Toast.makeText(RemittanceTransferActivity.this, "请确认打印纸安装正确", Toast.LENGTH_SHORT).show();
//                                    surePrintingpeperLayout.setVisibility(View.VISIBLE);
//                                    printingLayout.setVisibility(View.GONE);
//                                }
//                            });
//                        }
//                    }
//                });
//            }
//        }.start();
//    }


    /**
     * 打印
     */
    private void paint() {
        new Thread() {
            @Override
            public void run() {
                super.run();
                posFuncs.printerClearBuffer();
                posFuncs.printerAppendLargeTextAlignCenter("烟台银行 通用凭证");

                posFuncs.printerAppendTextline("交易时间 :" + time);
                posFuncs.printerAppendTextline("设备号 :" + Constants.YANTAI_TERMNO);
                posFuncs.printerAppendTextline("操作员 :" + SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""));
                posFuncs.printerAppendTextline("转出账号 :" + bindNum);
                posFuncs.printerAppendTextline("转入账号 :" + inputnumEdtext.getText().toString());
                posFuncs.printerAppendTextline("流水号 :" + rwNUm);
                if (Transfer_type.equals("other")) {
                    posFuncs.printerAppendTextline("业务类型 :" + "本行转他行转账");
                    posFuncs.printerAppendTextline("户名 :" + out_name);
                } else {
                    posFuncs.printerAppendTextline("业务类型 :" + "本行转本行转账");
                    posFuncs.printerAppendTextline("户名 :" + out_name);
                }
                if (inputMoneyEdtext.getText().toString().contains(".")) {
                    String moneys[] = inputMoneyEdtext.getText().toString().split("\\.");
                    if (moneys[1].length() == 1) {
                        String monses = moneys[0] + "." + moneys[1] + "0";
                        posFuncs.printerAppendTextline("交易金额 :" + monses);
                    } else {
                        posFuncs.printerAppendTextline("交易金额 :" + inputMoneyEdtext.getText().toString());
                    }

                } else {
                    posFuncs.printerAppendTextline("交易金额 :" + inputMoneyEdtext.getText().toString() + ".00");
                }
//                posFuncs.printerAppendTextline("交易金额 :" + inputMoneyEdtext.getText().toString());
                posFuncs.printerAppendTextline("凭证序号 :" + pz_nums);
                posFuncs.printerAppendTextline("客户签字确认 :");
                posFuncs.printerAppendTextline("--------------------------------------");
                posFuncs.printerAppendLargeTextAlignCenter("烟台银行 通用凭证");
                posFuncs.printerAppendTextline("交易时间 :" + time);
                posFuncs.printerAppendTextline("设备号 :" + Constants.YANTAI_TERMNO);
                posFuncs.printerAppendTextline("操作员 :" + SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""));
                String bindx = bindNum.substring(6, bindNum.length() - 5);
                String bindxs = "*";
                for (int i = 0; i < bindx.length(); i++) {
                    bindxs = bindxs + "*";
                }
                posFuncs.printerAppendTextline("转出账号 :" + bindNum.substring(0, 6) + bindxs + bindNum.substring(bindNum.length() - 4, bindNum.length()));
                String bindx_out = inputnumEdtext.getText().toString().substring(6, inputnumEdtext.getText().toString().length() - 5);
                String bindxs_out = "*";
                for (int i = 0; i < bindx_out.length(); i++) {
                    bindxs_out = bindxs_out + "*";
                }
                posFuncs.printerAppendTextline("转入账号 :" + inputnumEdtext.getText().toString().substring(0, 6) + bindxs_out + inputnumEdtext.getText().toString().substring(inputnumEdtext.getText().toString().length() - 4, inputnumEdtext.getText().toString().length()));
                posFuncs.printerAppendTextline("流水号 :" + rwNUm);
                if (Transfer_type.equals("other")) {
                    posFuncs.printerAppendTextline("业务类型 :" + "本行转他行转账");
                    String RemittanceNameone = out_name.substring(0, 1);
                    posFuncs.printerAppendTextline("户名 :" + out_name.replaceFirst(RemittanceNameone, "*"));
                } else {
                    posFuncs.printerAppendTextline("业务类型 :" + "本行转本行转账");
                    String RemittanceNameone = out_name.substring(0, 1);
                    posFuncs.printerAppendTextline("户名 :" + out_name.replaceFirst(RemittanceNameone, "*"));
                }
                if (inputMoneyEdtext.getText().toString().contains(".")) {
                    String moneys[] = inputMoneyEdtext.getText().toString().split("\\.");
                    if (moneys[1].length() == 1) {
                        String monses = moneys[0] + "." + moneys[1] + "0";
                        posFuncs.printerAppendTextline("交易金额 :" + monses);
                    } else {
                        posFuncs.printerAppendTextline("交易金额 :" + inputMoneyEdtext.getText().toString());
                    }

                } else {
                    posFuncs.printerAppendTextline("交易金额 :" + inputMoneyEdtext.getText().toString() + ".00");
                }
                posFuncs.printerAppendTextline("凭证序号 :" + pz_nums);
                posFuncs.printerAppendTextline("客户签字确认 :");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");


                posFuncs.startPrint(new PosCallbacks.PrintCallbacaks() {
                    @Override
                    public void onSuccess() {
                        Toast.makeText(RemittanceTransferActivity.this, "打印成功", Toast.LENGTH_SHORT).show();
                        finish();
                    }

                    @Override
                    public void onFailed(String error) {
                        if (error.equals("Lack Paper")) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(RemittanceTransferActivity.this, "请确认打印纸安装正确", Toast.LENGTH_SHORT).show();
                                    surePrintingpeperLayout.setVisibility(View.VISIBLE);
                                    printingLayout.setVisibility(View.GONE);
                                }
                            });
                        }
                    }
                });
            }
        }.start();
    }

    /**
     * 银行行名行号查询
     */
    public void excuteQB(String transn) {

        IsoMessage msg = null;
        QBInterface inter = new QBInterface();
        msg = inter.packRequest(transn, bank_type, inputBanknameEdtext.getText().toString());
        excuteRequest(msg, "qb");
    }

    /**
     * 读取卡
     */
    private void readCardTest() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                posFuncs.cardReaderConfig(true, true, true);

                posFuncs.emvSimpleFlow(new PosCallbacks.EmvTransStartCallbacks() {
                    @Override
                    public void onDetectCard(String type) {
                        CardType = type;
                        Log.e("", type);
                    }

                    @Override
                    public void onConfirmCardInfo(String pan) {
                        Logger.e("pan" + pan);
                        bindNum = pan;
                        if (bindNum.equals("")) {
                            Toast.makeText(RemittanceTransferActivity.this, "请插入卡", Toast.LENGTH_SHORT).show();
                        } else {

                            Toast.makeText(getApplicationContext(), pan, Toast.LENGTH_SHORT).show();
                            posFuncs.emvConfirmCardInfo(EmvConstants.CONFIRM_OK);

                        }
                    }

                    @Override
                    public void onOlinePinEntered(String enc, boolean is_no_pin) {

                    }

                    @Override
                    public void onSuccess(Bundle data) {
                        if (!data.isEmpty()) {
                            pleaseInputIccardLayout.setVisibility(View.GONE);
                            ficationingLayout.setVisibility(View.VISIBLE);

                            Log.e("", data.getString(EmvConstants.FEILD_55));
                            //如果是磁条卡，就获取二磁信息、上传给银行接口
                            // IC Card    MAG Card    RF Card
                            if (CardType.equals("MAG Card")) {
                                track2Data = data.getString(EmvConstants.TRACK2);
                                track3Data = data.getString(EmvConstants.TRACK3);

                            } else {
                                track2Data = Utils.formatField57(Utils.getValueFromIccData("57", data.getString(EmvConstants.FEILD_55)));
                                s_number = Utils.getValueFromIccData("5f34", data.getString(EmvConstants.FEILD_55));
                                String[] tags =
                                        {
                                                "9F26", "9F27", "9F10", "9F37", "9F36", "95",
                                                "9A", "9C", "9F02", "5F2A", "82", "9F1A", "9F03", "9F33", "9F34", "9F35",
                                                "9F1E", "84", "9F09", "9F41"
                                        };
                                Field55 = Utils.getField55(tags, data.getString(EmvConstants.FEILD_55));
                                Logger.e("f55" + Field55);
                                Logger.e(s_number + "s_numbers_number");
                            }
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                                    Logger.e("第一次获取rz" + num);
                                    excuteVTA(String.valueOf(num), bindNum, CardType, track2Data);
                                    SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                                    Logger.e("第二次获取rz" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0));
                                }
                            }).start();
                        }

                    }

                    @Override
                    public void onFailed(String error) {
                        Toast.makeText(RemittanceTransferActivity.this, error, Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }).start();
    }

    private void tradeWithCards(final double money) {
        PinPad.initPinPad(posFuncs);
        new Thread() {
            @Override
            public void run() {

                posFuncs.cardReaderConfig(true, true, true);
                posFuncs.emvTransStart(new PosCallbacks.EmvTransStartCallbacks() {

                    @Override
                    public void onDetectCard(String type) {
                        CardType = type;
                    }

                    @Override
                    public void onConfirmCardInfo(final String pan) {
                        bindNum = pan;
                        Logger.e(pan + "pan");
                        posFuncs.emvConfirmCardInfo(EmvConstants.CONFIRM_OK);

                    }

                    @Override
                    public void onOlinePinEntered(String enc, boolean is_no_pin) {
                        if (!is_no_pin) {

                            try {
                                String pin = PinPad.getPin(bindNum, enc);
                                password = pin;
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }

                    @Override
                    public void onSuccess(Bundle data) {

                        String channel = data.getString(EmvConstants.CHANNEL);
                        if (EmvConstants.CHANNEL_MAGCARD.equals(channel)) {
//                            appendInfo("MagCard Used\n");
//                            appendInfo("Track1: " + data.getString(EmvConstants.TRACK1) + "\n");
//                            appendInfo("Track2: " + data.getString(EmvConstants.TRACK2) + "\n");
//                            appendInfo("Track3: " + data.getString(EmvConstants.TRACK3) + "\n");
//                            appendInfo("\nFinish\n");
//                            setEmvProcessStatus(false);
                        } else if (EmvConstants.CHANNEL_ICC.equals(channel)) {
//                            appendInfo("ICCard Used\n");
                            track2Data = Utils.formatField57(Utils.getValueFromIccData("57", data.getString(EmvConstants.FEILD_55)));
                            s_number = Utils.getValueFromIccData("5f34", data.getString(EmvConstants.FEILD_55));
                            if (transition == TRANSITION_DZH) {
                                new Thread(new Runnable() {
                                    @Override
                                    public void run() {
                                        num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                                        Logger.e("第一次获取rz" + num);
                                        excuteVTA(String.valueOf(num), bindNum, CardType, track2Data);
                                        SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                                        Logger.e("第二次获取rz" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0));
                                    }
                                }).start();
                            }
                            String ac_type = data.getString(EmvConstants.AC_TYPE);
                            Logger.e("ac_type" + ac_type);
                            Logger.e("Ac Type: " + data.getString(EmvConstants.AC_TYPE) + "\n");
                            Logger.e("Field 55: " + data.getString(EmvConstants.FEILD_55) + "\n");
                            String[] tags =
                                    {
                                            "9F26", "9F27", "9F10", "9F37", "9F36", "95",
                                            "9A", "9C", "9F02", "5F2A", "82", "9F1A", "9F03", "9F33", "9F34", "9F35",
                                            "9F1E", "84", "9F09", "9F41"
                                    };
                            Field55 = Utils.getField55(tags, data.getString(EmvConstants.FEILD_55));
                            Logger.e("f55" + Field55);
                            if (EmvConstants.AC_TYPE_ARQC.equals(ac_type)) {

                                Bundle bundle = new Bundle();
                                bundle.putString(EmvConstants.RESPONSE_CODE, "3030");
                                posFuncs.emvOnlineResult(new PosCallbacks.EmvOnlineResultCallbacks() {
                                    @Override
                                    public void onSuccess(Bundle data) {
                                        Logger.e("Ac Type: " + data.getString(EmvConstants.AC_TYPE) + "\n");
                                        Logger.e("Field 55: " + data.getString(EmvConstants.FEILD_55) + "\n");

                                    }

                                    @Override
                                    public void onFailed(String error) {

                                    }
                                }, bundle);
                            } else {

                            }
                        } else if (EmvConstants.CHANNEL_ICCL.equals(channel)) {
                            Logger.e("Ac Type: " + data.getString(EmvConstants.AC_TYPE) + "\n");
                            Logger.e("Field 55: " + data.getString(EmvConstants.FEILD_55) + "\n");

                        }

                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (transition == TRANSITION_HZD) {
                                    inputMoneyLayout.setVisibility(View.GONE);
                                    sureDealInfoNumtext.setText(bindNum);
                                    sureDealInfoMoneytext.setText("￥" + inputMoneyEdtext.getText().toString());
                                    sureDealInfoType.setText(live_to_atfix + "" + save_time);
                                    sureDealInfoLayout.setVisibility(View.VISIBLE);
                                    sureDealInfoTitle.setText("请确认转换信息");
                                } else if (transition == TRANSITION_DZH) {
                                    new Thread(new Runnable() {
                                        @Override
                                        public void run() {
                                            num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                                            Logger.e("第一次获取rz" + num);
                                            excuteSBA(String.valueOf(num), CardType);
                                            SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                                            Logger.e("第二次获取rz" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0));
                                        }
                                    }).start();

                                } else if (Transfer_type == "transbetween") {
                                    inputMoneyLayout.setVisibility(View.GONE);
                                    sureDealInfoNumtext.setText(bindNum);
                                    sureDealInfoMoneytext.setText("￥" + inputMoneyEdtext.getText().toString());
                                    sureDealInfoType.setText(live_to_atfix + "" + save_time);
                                    sureDealInfoLayout.setVisibility(View.VISIBLE);
                                    sureDealInfoTitle.setText("请确认转换信息");
                                } else {
                                    inputMoneyLayout.setVisibility(View.GONE);
                                    selectWaytozhangLayout.setVisibility(View.VISIBLE);
                                }

                            }
                        });
                    }

                    @Override
                    public void onFailed(String error) {
                        Logger.e(error + "error");
                    }
                }, (int) money, 0);
            }
        }.start();
    }

    /**
     * 调取键盘
     */
    private void enterPin(final String bindNum, final double money) {
        Logger.e(money + "");
        new Thread() {
            @Override
            public void run() {
                posFuncs.enterPin(new PosCallbacks.EnterPinCallbacks() {
                    @Override
                    public void onSuccess(final String enc, boolean is_no_pin) {
                        if (is_no_pin) {

                        } else {
                            Logger.e("", enc);
                            password = enc;
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Logger.e("aaaaaaaadadsa");
                                    if (transition == TRANSITION_HZD) {
                                        inputMoneyLayout.setVisibility(View.GONE);
                                        sureDealInfoNumtext.setText(bindNum);
                                        sureDealInfoMoneytext.setText("￥" + inputMoneyEdtext.getText().toString());
                                        sureDealInfoType.setText(live_to_atfix + "" + save_time);
                                        sureDealInfoLayout.setVisibility(View.VISIBLE);
                                        sureDealInfoTitle.setText("请确认转换信息");
                                    } else if (transition == TRANSITION_DZH) {
                                        new Thread(new Runnable() {
                                            @Override
                                            public void run() {
                                                num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                                                Logger.e("第一次获取rz" + num);
                                                excuteSBA(String.valueOf(num), CardType);
                                                SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                                                Logger.e("第二次获取rz" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0));
                                            }
                                        }).start();

                                    } else if (Transfer_type == "transbetween") {
                                        inputMoneyLayout.setVisibility(View.GONE);
                                        sureDealInfoNumtext.setText(bindNum);
                                        sureDealInfoMoneytext.setText("￥" + inputMoneyEdtext.getText().toString());
                                        sureDealInfoType.setText(live_to_atfix + "" + save_time);
                                        sureDealInfoLayout.setVisibility(View.VISIBLE);
                                        sureDealInfoTitle.setText("请确认转换信息");
                                    } else {
                                        inputMoneyLayout.setVisibility(View.GONE);
                                        selectWaytozhangLayout.setVisibility(View.VISIBLE);
                                    }

                                }
                            });
                        }
                    }

                    @Override
                    public void onFail(String error) {
                        Toast.makeText(RemittanceTransferActivity.this, "交易结束", Toast.LENGTH_SHORT).show();
                        if (!error.equals(null)) {
                            finish();
                        }

                    }

                    @Override
                    public void onInput(int input_num) {
                        Log.e("", String.valueOf(input_num));
                    }
                }, bindNum, (int) money);
            }
        }.start();
    }

    /**
     * 子账户查询
     */
    public void excuteSBA(String transn, String CardType) {
        String c_bin_info = SpUtils.getSPUtil(getApplicationContext()).getString("c_bin_info", "null");
        Gson gson = new Gson();
        List<CardBinInfo_bean> beans = gson.fromJson(c_bin_info, new TypeToken<List<CardBinInfo_bean>>() {
        }.getType());
        IsoMessage msg = null;
        SBAInterface inter = new SBAInterface();
        msg = inter.packRequest(bindNum, beans, transn, track2Data, track3Data, password, CardType, String.valueOf(1), Field55, s_number, f59num, f59data);
        excuteRequest(msg, "zhcx");
    }

    /**
     * 账户验证
     */
    public void excuteVTA(String transn, String bindNum, String CardTYpe, String track2Data) {
        String c_bin_info = SpUtils.getSPUtil(getApplicationContext()).getString("c_bin_info", "null");
        Gson gson = new Gson();
        List<CardBinInfo_bean> beans = gson.fromJson(c_bin_info, new TypeToken<List<CardBinInfo_bean>>() {
        }.getType());
        IsoMessage msg = null;
        VTAInterface inter = new VTAInterface();
        msg = inter.packRequest(bindNum, beans, transn, track2Data, CardTYpe, String.valueOf(2), s_number);
        excuteRequest(msg, "zhrz");
    }

    /**
     * 转账 本行转本行
     */
    private void enterTSF(String transn, String time) {
        String c_bin_info = SpUtils.getSPUtil(getApplicationContext()).getString("c_bin_info", "null");
        Gson gson = new Gson();
        List<CardBinInfo_bean> beans = gson.fromJson(c_bin_info, new TypeToken<List<CardBinInfo_bean>>() {
        }.getType());
        IsoMessage msg = null;
        TSFInterface inter = new TSFInterface();
        msg = inter.packRequest(bindNum, inputnumEdtext.getText().toString(), beans,
                transn, password, CardType, track2Data, track3Data, String.valueOf(1), inputMoneyEdtext.getText().toString(), s_number, Field55, time);
        excuteRequest(msg, "bzb");
    }

    /**
     * 转账 本行转他行
     *
     * @param
     */
    private void enterTH(String transn) {
        String c_bin_info = SpUtils.getSPUtil(getApplicationContext()).getString("c_bin_info", "null");
        Gson gson = new Gson();
        List<CardBinInfo_bean> beans = gson.fromJson(c_bin_info, new TypeToken<List<CardBinInfo_bean>>() {
        }.getType());
        IsoMessage msg = null;
        THInterface inter = new THInterface();
        msg = inter.packRequest(bindNum, inputnumEdtext.getText().toString(), beans,
                transn, track2Data, track3Data, CardType, password, String.valueOf(1), Field55, jgh
                , out_name, bind_num, inputNameEdtext.getText().toString(), inputMoneyEdtext.getText().toString(), s_number, run_time);
        excuteRequest(msg, "bzt");
    }

    /**
     * 定活互转
     * 活转定
     *
     * @param
     */
    private void enterLTF(String transn) {
        String c_bin_info = SpUtils.getSPUtil(getApplicationContext()).getString("c_bin_info", "null");
        Gson gson = new Gson();
        List<CardBinInfo_bean> beans = gson.fromJson(c_bin_info, new TypeToken<List<CardBinInfo_bean>>() {
        }.getType());
        IsoMessage msg = null;
        LTFInterface inter = new LTFInterface();
        msg = inter.packRequest(bindNum, beans, transn, track2Data, track3Data, CardType, password, "1", Field55,
                live_to_atfix, save_time, "hzd", conver_saving, inputCustomanagerEdtext.getText().toString(), jgh, select_cq
                , "", inputMoneyEdtext.getText().toString(), s_number, run_time);
        excuteRequest(msg, "hzd");
    }

    /**
     * 定活互转
     * 定转活
     *
     * @param
     */
    private void enterDZH(String transn) {
        String c_bin_info = SpUtils.getSPUtil(getApplicationContext()).getString("c_bin_info", "null");
        Gson gson = new Gson();
        List<CardBinInfo_bean> beanss = gson.fromJson(c_bin_info, new TypeToken<List<CardBinInfo_bean>>() {
        }.getType());
        IsoMessage msg = null;
        LTFInterface inter = new LTFInterface();
        msg = inter.packRequest(bindNum, beanss, transn, track2Data, track3Data, CardType, password, "1", Field55,
                Select_beans.get(positions).getZhnum(), save_time, "dzh", conver_saving, inputCustomanagerEdtext.getText().toString(), jgh, select_cq,
                Select_beans.get(positions).getNum(), Select_beans.get(positions).getBalanceofAccount(), s_number, run_time);
        excuteRequest(msg, "dzh");
    }

    /**
     * 自动冲正
     */
    public void excuteCZ(String transn) {

        IsoMessage msg = null;
        CZInterface inter = new CZInterface();
        msg = inter.packRequest(bindNum, bindNum, Constants.DEMO_F102, cz_num, cz_time, run_time, transn, track2Data, track3Data, CardType, password, String.valueOf(1), Field55, inputMoneyEdtext.getText().toString(), s_number);
        excuteRequest(msg, "zdcz");
    }

    private void excuteRequest(IsoMessage msg, final String op_type) {

        byte[] data = msg.writeData();
        // ��д����ͷ��7�򳤶�ֵ
        int hlen = Constants.ATMP_HEADER_LENGTH;
        int bodylen = data.length - hlen;
        String headF7 = ServiceCommon.appendZero(bodylen, 4);
        System.arraycopy(headF7.getBytes(), 0, data, 28, 4);
        // ����MAC
        if (msg.getField(128) != null) {
//            int start = hlen;
//            int length = data.length - start - 8;
//            byte[] inmac = new byte[length];
//            byte[] outmac = new byte[16];
//            System.arraycopy(data, start, inmac, 0, length);
//            Logger.e("MAC����=[{}]" + HexT.byteArr2HexStr(inmac));
//            Logger.e(Constants.YANTAI_MACKEY);
//            String mackey = Constants.YANTAI_MACKEY;
//            // MAC99�㷨makֻ��Ҫ16�ֽ���Կ
//            if (mackey.length() > 16) {
//                mackey = mackey.substring(0, 16);
//            }
//            DES3.getMacBlock_99(inmac, mackey.getBytes(), outmac);
//            System.arraycopy(outmac, 0, data, data.length - 8, 8);
//            Logger.e("����MAC=[{}]" + new String(outmac).substring(0, 8));
            int start = hlen;
            int length = data.length - start - 8;
            byte[] inmac = new byte[length];
            byte[] outmac = new byte[16];
            System.arraycopy(data, start, inmac, 0, length);
            System.out.println("MAC数据=[" + HexT.byteArr2HexStr(inmac) + "]");
            String mackey = Constants.YANTAI_MACKEY;

            if (Constants.isSM) {
                // SM4 MAC919算法
                byte[] mkey = HexT.hexstr2ByteArr(mackey);
                String macval = SMS4.sms4MacBlock_919(inmac, mkey);
                outmac = macval.getBytes();
            } else {
                // MAC99算法mak只需要16字节密钥
                if (mackey.length() > 16) {
                    mackey = mackey.substring(0, 16);
                }
                DES3.getMacBlock_99(inmac, mackey.getBytes(), outmac);
            }

            System.arraycopy(outmac, 0, data, data.length - 8, 8);
            System.out.println("请求MAC=[" + new String(outmac).substring(0, 8) + "]");
        }
        byte[] send = null;
        // ���ļ��ܣ���������ʱ��ҵ���ױ��뱨�ļ���
        String encflag = msg.getHeadStringValue(4);
        if ("1".equals(encflag)) {
            String tdk = Constants.YANTAI_TDKKEY;
            int lenr = 8 - bodylen % 8;
            byte[] head = new byte[hlen];
            byte[] decdata = new byte[bodylen + lenr];
            System.arraycopy(data, 0, head, 0, hlen);
            System.arraycopy(data, hlen, decdata, 0, bodylen);
            byte[] encdata = DES3.des3Packet(decdata, tdk.getBytes());
            send = new byte[hlen + encdata.length];
            System.arraycopy(head, 0, send, 0, hlen);
            System.arraycopy(encdata, 0, send, hlen, encdata.length);

        } else if ("3".equals(encflag)) {
            String tdk = Constants.YANTAI_TDKKEY;
            byte[] tdkey = HexT.hexstr2ByteArr(tdk);
            byte[] h7 = new byte[4];
            System.arraycopy(data, 28, h7, 0, 4);
            int orilen = Integer.parseInt(new String(h7));
            int enclen = data.length - Constants.ATMP_HEADER_LENGTH;
            byte[] head = new byte[Constants.ATMP_HEADER_LENGTH];
            byte[] encdata = new byte[enclen];
            System.arraycopy(data, 0, head, 0, Constants.ATMP_HEADER_LENGTH);
            System.arraycopy(data, Constants.ATMP_HEADER_LENGTH, encdata, 0, enclen);
            byte[] decdata = SMS4.unsms4Packet(encdata, tdkey);

            send = new byte[Constants.ATMP_HEADER_LENGTH + orilen];
            System.arraycopy(head, 0, send, 0, Constants.ATMP_HEADER_LENGTH);
            System.arraycopy(decdata, 0, send, Constants.ATMP_HEADER_LENGTH, orilen);
        } else {
            send = data;
        }

        CommAdapter adapter = new CommAdapter(Constants.IP, 3551);
        adapter.setHeadlen(4); // ����ͷ��4�ֽ�
        byte[] recv = adapter.doComm(send);

        byte[] recv2 = null;
        byte[] b = new byte[1];
        System.arraycopy(recv, 11, b, 0, 1);
        String rspenc = new String(b);
        Logger.e("Ӧ���ļ��ܱ�־:[{}]" + rspenc);
        if ("1".equals(rspenc)) {
            String tdk = Constants.YANTAI_TDKKEY;
            byte[] h7 = new byte[4];
            System.arraycopy(recv, 28, h7, 0, 4);
            int orilen = Integer.parseInt(new String(h7));
            int enclen = recv.length - Constants.ATMP_HEADER_LENGTH;
            byte[] head = new byte[Constants.ATMP_HEADER_LENGTH];
            byte[] encdata = new byte[enclen];
            System.arraycopy(recv, 0, head, 0, Constants.ATMP_HEADER_LENGTH);
            System.arraycopy(recv, Constants.ATMP_HEADER_LENGTH, encdata, 0, enclen);
            byte[] decdata = DES3.undes3Packet(encdata, tdk.getBytes());

            recv2 = new byte[Constants.ATMP_HEADER_LENGTH + orilen];
            System.arraycopy(head, 0, recv2, 0, Constants.ATMP_HEADER_LENGTH);
            System.arraycopy(decdata, 0, recv2, Constants.ATMP_HEADER_LENGTH, orilen);
        } else {
            recv2 = recv;
        }

        IsoMessage rsp = null;
        MessageFactory<IsoMessage> fac = new MessageFactory<IsoMessage>();
        try {
            rsp = fac.parseMessage(recv2, 32);
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        String respcode = rsp.getStringValue(39);
        if ("00".equals(respcode)) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (op_type.equals("zhrz")) {
                        Toast.makeText(getApplicationContext(), "验证成功", Toast.LENGTH_SHORT).show();
                    } else if (op_type.equals("bzb")) {

                    }
                }
            });
            unpackReSpone(rsp, op_type);
        } else if ("96".equals(respcode)) {

            Gson gson = new Gson();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");// HH:mm:ss
            //获取当前时间
            Date date = new Date(System.currentTimeMillis());
            if (op_type.equals("bzb")) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        String time = DateUtil.getCurrentTime(DateUtil.M_TIME_PATTERN);
                        run_time = time;
                        num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                        Logger.e("第一次获取" + num);
                        excuteCZ(String.valueOf(num));
                        SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                        Logger.e("第二次获取" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 1000));

                    }
                }).start();


                Logger.e("Date获取当前日期时间" + simpleDateFormat.format(date).replace("/", "") + "UN_DATA");
                StatisticalData_bean bean = new StatisticalData_bean(rwNUm, inputMoneyEdtext.getText().toString(), time, "本转本转账汇款", bindNum, out_name, SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), String.valueOf(pz_nums));

                String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", ""), "");

                List<StatisticalData_bean> beans = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
                }.getType());
                beans.add(bean);
                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "UN_DATA", gson.toJson(beans));
                finish();
            } else if (op_type.equals("bzt")) {
                Logger.e("Date获取当前日期时间" + simpleDateFormat.format(date).replace("/", "") + "UN_DATA");
                StatisticalData_bean bean = new StatisticalData_bean(rwNUm, inputMoneyEdtext.getText().toString(), time, "本转他转账汇款", bindNum, inputNameEdtext.getText().toString(), SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), String.valueOf(pz_nums));
                String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", ""), "");

                List<StatisticalData_bean> beans = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
                }.getType());
                beans.add(bean);
                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "UN_DATA", gson.toJson(beans));
                finish();
            } else if (op_type.equals("hzd")) {
                Logger.e("Date获取当前日期时间" + simpleDateFormat.format(date).replace("/", "") + "UN_DATA");
                StatisticalData_bean bean = new StatisticalData_bean(rwNUm, inputMoneyEdtext.getText().toString(), time, "活转定", bindNum, name, SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), String.valueOf(pz_nums));
                String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", ""), "");

                List<StatisticalData_bean> beans = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
                }.getType());
                beans.add(bean);
                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "UN_DATA", gson.toJson(beans));
                finish();
            } else if (op_type.equals("dzh")) {
                Logger.e("Date获取当前日期时间" + simpleDateFormat.format(date).replace("/", "") + "UN_DATA");
                StatisticalData_bean bean = new StatisticalData_bean(rwNUm, Select_beans.get(positions).getBalanceofAccount(), time, "定转活", bindNum, name, SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), String.valueOf(pz_nums));
                String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", ""), "");

                List<StatisticalData_bean> beans = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
                }.getType());
                beans.add(bean);
                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "UN_DATA", gson.toJson(beans));
                finish();
            }

        } else {
            f39 = rsp.getStringValue(39);
            if (op_type.equals("bzb")) {
                Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
                try {
                    up_rundataUtils.packRequest("0200", "400000",
                            inputMoneyEdtext.getText().toString().trim(), "1", run_time, String.valueOf(num), f39);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else if (op_type.equals("zdcz")) {
                Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
                try {
                    up_rundataUtils.packRequest("0420", "440000",
                            "000000000000000", "3", run_time, String.valueOf(num), f39);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else if (op_type.equals("bzt")) {

                Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
                try {
                    up_rundataUtils.packRequest("0200", "400000",
                            inputMoneyEdtext.getText().toString().trim(), "1", run_time, String.valueOf(num), f39);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else if (op_type.equals("hzd")) {
                Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
                try {
                    up_rundataUtils.packRequest("0200", "440000",
                            inputMoneyEdtext.getText().toString().trim(), "1", run_time, String.valueOf(num), f39);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else if (op_type.equals("dzh")) {

                Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
                try {
                    up_rundataUtils.packRequest("0200", "440000",
                            Select_beans.get(positions).getBalanceofAccount(), "1", run_time, String.valueOf(num), f39);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            Logger.e("����ʧ��:[{}]-[{}]" + respcode + rsp.getStringValue(40));
            final IsoMessage finalRsp = rsp;
            RemittanceTransferActivity.this.runOnUiThread(new Runnable() {
                @SuppressLint("WrongConstant")
                @Override
                public void run() {
                    if (finalRsp.getStringValue(40).equals("该功能尚不支持")) {
                        Toast.makeText(getApplicationContext(), "卡号错误", 3000).show();
                    } else {
                        Toast toast = Toast.makeText(getApplicationContext(), finalRsp.getStringValue(40), Toast.LENGTH_LONG);
                        showMyToast(toast, 5 * 1000);
                    }
                }
            });

            this.finish();
        }
    }

    public void showMyToast(final Toast toast, final int cnt) {
        final Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                toast.show();
            }
        }, 0, 3000);
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                toast.cancel();
                timer.cancel();
            }
        }, cnt);
    }

    private void unpackReSpone(IsoMessage response, String op_type) {
        rwNUm = response.getStringValue(37);
        f39 = response.getStringValue(39);
        Logger.e(rwNUm);
        if (op_type.equals("zhrz")) {
            SpUtils.getSPUtil(getApplicationContext()).putString("all_make_type", "zhrz");
//            账户验证
            String f123 = response.getStringValue(123);

            String f123s[] = f123.split("\\|");
            out_name = f123s[2];
            Logger.e(out_name + "out_name");
            jgh = f123s[0];
            if (sureinput.equals("out")) {
                in_name = f123s[2];

                out_name = f123s[2];
            } else {
//                out_name = f123s[2].substring(0, 5).replace(" ", "");
                out_name = f123s[2];
            }
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    handler = new Handler();
                    runnable = new Runnable() {
                        @Override
                        public void run() {
                            //是否转他行
                            if (Transfer_type.equals("other")) {
                                ficationingLayout.setVisibility(View.GONE);
                                showSelectbankLayout.setVisibility(View.VISIBLE);
                            } else if (transition == TRANSITION_HZD) {
//                                活期转定期账户验证
                                ficationingLayout.setVisibility(View.GONE);
                                inputCustomanagerLayout.setVisibility(View.VISIBLE);
                            } else if (transition == TRANSITION_DZH) {
////                               定期转活期账户验证
//                                enterPin(bindNum, 0);
                            } else {
                                if (sureinput.equals("out")) {
                                    //汇款账号确定 认证成功
                                    ficationingLayout.setVisibility(View.GONE);
                                    inputMoneyLayout.setVisibility(View.VISIBLE);
                                } else {
                                    //读取账号 成功
                                    ficationingLayout.setVisibility(View.GONE);
                                    inputNumLayout.setVisibility(View.VISIBLE);
                                }
                            }
                        }
                    };
                    handler.postDelayed(runnable, 1000);
                }
            });
        } else if (op_type.equals("bzb")) {
            Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
            try {
                up_rundataUtils.packRequest("0200", "400000",
                        inputMoneyEdtext.getText().toString().trim(), "0", run_time, String.valueOf(num), f39);
            } catch (IOException e) {
                e.printStackTrace();
            }


            SpUtils.getSPUtil(getApplicationContext()).putString("all_make_type", "bzb");
            PzGetUtils pzGetUtils = new PzGetUtils();
            pz_nums = pzGetUtils.pzutil(getApplication());


//            本行转本行
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    successRemittanceType.setText(account_type);
                    successRemittanceNum.setText(inputnumEdtext.getText().toString());
                    successRemittanceMoney.setText("￥" + inputMoneyEdtext.getText().toString());
                    successRemittanceName.setText(out_name);
                    dealingLayout.setVisibility(View.GONE);
                    successRemittanceLayout.setVisibility(View.VISIBLE);
                }
            });
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");// HH:mm:ss
            //获取当前时间
            Date date = new Date(System.currentTimeMillis());
            Logger.e("Date获取当前日期时间" + simpleDateFormat.format(date).replace("/", ""));
            StatisticalData_bean bean = new StatisticalData_bean(rwNUm, inputMoneyEdtext.getText().toString(), time, "本转本转账汇款", bindNum, out_name, SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), String.valueOf(pz_nums));
            String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", ""), "");
            Gson gson = new Gson();
            List<StatisticalData_bean> beans = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
            }.getType());
            beans.add(bean);
            SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", ""), gson.toJson(beans));

            //汇总查询
            String STAT_DATAALL = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", "");
            List<Summary_Bean> beanalls = gson.fromJson(STAT_DATAALL, new TypeToken<List<Summary_Bean>>() {
            }.getType());
            if (!beanalls.get(0).getZzhk().equals("")) {
                String data[] = beanalls.get(0).getZzhk().split(",");
                int num = Integer.valueOf(data[1]) + 1;
                double money;

                Logger.e(data[0] + "aaaaaaaaaaa" + inputMoneyEdtext.getText().toString());
                if (data[0].contains(".") && inputMoneyEdtext.getText().toString().contains(".")) {
                    money = Double.parseDouble(data[0]) + Double.parseDouble(inputMoneyEdtext.getText().toString());
                } else if (data[0].contains(".") && !inputMoneyEdtext.getText().toString().contains(".")) {
                    money = Double.parseDouble(data[0]) + Integer.parseInt(inputMoneyEdtext.getText().toString());
                } else if (!data[0].contains(".") && inputMoneyEdtext.getText().toString().contains(".")) {
                    money = Integer.valueOf(data[0]) + Double.parseDouble(inputMoneyEdtext.getText().toString());
                } else {
                    money = Integer.valueOf(data[0]) + Integer.valueOf(inputMoneyEdtext.getText().toString());
                }
//                BigDecimal n = new BigDecimal("0");


                String Zzhk = money + "," + num;
                Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), Zzhk, beanalls.get(0).getYdhf(), beanalls.get(0).getLthf(), beanalls.get(0).getSgcc(), beanalls.get(0).getDzh(), beanalls.get(0).getHzd(), beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), beanalls.get(0).getHnyqy(), beanalls.get(0).getHnyjy());
                beanalls.clear();
                beanalls.add(summary_bean);
                Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));

            } else {
                int num = 1;
                double money;
                if (inputMoneyEdtext.getText().toString().contains(".")) {
                    money = Double.parseDouble(inputMoneyEdtext.getText().toString());
                    String Zzhk = money + "," + num;
                    Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), Zzhk, beanalls.get(0).getYdhf(), beanalls.get(0).getLthf(), beanalls.get(0).getSgcc(), beanalls.get(0).getDzh(), beanalls.get(0).getHzd(), beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), beanalls.get(0).getHnyqy(), beanalls.get(0).getHnyjy());
                    beanalls.clear();
                    beanalls.add(summary_bean);
                    Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                    SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));

                } else {

                    money = Integer.valueOf(inputMoneyEdtext.getText().toString());
                    String Zzhk = money + "," + num;
                    Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), Zzhk, beanalls.get(0).getYdhf(), beanalls.get(0).getLthf(), beanalls.get(0).getSgcc(), beanalls.get(0).getDzh(), beanalls.get(0).getHzd(), beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), beanalls.get(0).getHnyqy(), beanalls.get(0).getHnyjy());
                    beanalls.clear();
                    beanalls.add(summary_bean);
                    Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                    SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));

                }

            }

        } else if (op_type.equals("qb")) {
            SpUtils.getSPUtil(getApplicationContext()).putString("all_make_type", "qb");
            Logger.e(response.getStringValue(123));
            final String f123s[] = response.getStringValue(123).split("\\|");
            bind_num = f123s[0].substring(2, f123s[0].length());
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    bankInfoLayout.setVisibility(View.VISIBLE);
                    showSelectbankLayout.setVisibility(View.GONE);
                    bankInfoName.setText(f123s[1]);
                    bankInfoNum.setText("序号: " + bind_num);
                }
            });
        } else if (op_type.equals("bzt")) {

            Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
            try {
                up_rundataUtils.packRequest("0200", "400000",
                        inputMoneyEdtext.getText().toString().trim(), "0", run_time, String.valueOf(num), f39);
            } catch (IOException e) {
                e.printStackTrace();
            }

            SpUtils.getSPUtil(getApplicationContext()).putString("all_make_type", "bzt");
            PzGetUtils pzGetUtils = new PzGetUtils();
            pz_nums = pzGetUtils.pzutil(getApplication());

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");// HH:mm:ss
            //获取当前时间
            Date date = new Date(System.currentTimeMillis());
            Logger.e("Date获取当前日期时间" + simpleDateFormat.format(date).replace("/", ""));
            StatisticalData_bean bean = new StatisticalData_bean(rwNUm, inputMoneyEdtext.getText().toString(), time, "本转他转账汇款", bindNum, inputNameEdtext.getText().toString(), SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), String.valueOf(pz_nums));
            String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", ""), "");
            Gson gson = new Gson();
            List<StatisticalData_bean> beans = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
            }.getType());
            beans.add(bean);
            SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", ""), gson.toJson(beans));

            //汇总查询
            String STAT_DATAALL = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", "");
            List<Summary_Bean> beanalls = gson.fromJson(STAT_DATAALL, new TypeToken<List<Summary_Bean>>() {
            }.getType());
            if (!beanalls.get(0).getZzhk().equals("")) {
                String data[] = beanalls.get(0).getZzhk().split(",");
                int num = Integer.valueOf(data[1]) + 1;
                double money;

                Logger.e(data[0] + "aaaaaaaaaaa" + inputMoneyEdtext.getText().toString());
                if (data[0].contains(".") && inputMoneyEdtext.getText().toString().contains(".")) {
                    money = Double.parseDouble(data[0]) + Double.parseDouble(inputMoneyEdtext.getText().toString());
                } else if (data[0].contains(".") && !inputMoneyEdtext.getText().toString().contains(".")) {
                    money = Double.parseDouble(data[0]) + Integer.parseInt(inputMoneyEdtext.getText().toString());
                } else if (!data[0].contains(".") && inputMoneyEdtext.getText().toString().contains(".")) {
                    money = Integer.valueOf(data[0]) + Double.parseDouble(inputMoneyEdtext.getText().toString());
                } else {
                    money = Integer.valueOf(data[0]) + Integer.valueOf(inputMoneyEdtext.getText().toString());
                }
//                BigDecimal n = new BigDecimal("0");


                String getZzhk = money + "," + num;
                Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), getZzhk, beanalls.get(0).getYdhf(), beanalls.get(0).getLthf(), beanalls.get(0).getSgcc(), beanalls.get(0).getDzh(), beanalls.get(0).getHzd(), beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), beanalls.get(0).getHnyqy(), beanalls.get(0).getHnyjy());
                beanalls.clear();
                beanalls.add(summary_bean);
                Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));

            } else {
                int num = 1;
                double money;
                if (inputMoneyEdtext.getText().toString().contains(".")) {
                    money = Double.parseDouble(inputMoneyEdtext.getText().toString());
                    String getZzhk = money + "," + num;
                    Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), getZzhk, beanalls.get(0).getYdhf(), beanalls.get(0).getLthf(), beanalls.get(0).getSgcc(), beanalls.get(0).getDzh(), beanalls.get(0).getHzd(), beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), beanalls.get(0).getHnyqy(), beanalls.get(0).getHnyjy());
                    beanalls.clear();
                    beanalls.add(summary_bean);
                    Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                    SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));

                } else {
                    money = Integer.valueOf(inputMoneyEdtext.getText().toString());
                    String getZzhk = money + "," + num;
                    Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), getZzhk, beanalls.get(0).getYdhf(), beanalls.get(0).getLthf(), beanalls.get(0).getSgcc(), beanalls.get(0).getDzh(), beanalls.get(0).getHzd(), beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), beanalls.get(0).getHnyqy(), beanalls.get(0).getHnyjy());
                    beanalls.clear();
                    beanalls.add(summary_bean);
                    Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                    SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));
                }
            }


            runOnUiThread(new Runnable() {
                @Override
                public void run() {
//                    本行转他行
                    successRemittanceType.setText(account_type);
                    successRemittanceNum.setText(inputnumEdtext.getText().toString());
                    successRemittanceMoney.setText("￥" + inputMoneyEdtext.getText().toString());
                    successRemittanceName.setText(inputNameEdtext.getText().toString());
                    dealingLayout.setVisibility(View.GONE);
                    successRemittanceLayout.setVisibility(View.VISIBLE);
                }
            });
        } else if (op_type.equals("hzd")) {
            Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
            try {
                up_rundataUtils.packRequest("0200", "440000",
                        inputMoneyEdtext.getText().toString().trim(), "0", run_time, String.valueOf(num), f39);
            } catch (IOException e) {
                e.printStackTrace();
            }


            SpUtils.getSPUtil(getApplicationContext()).putString("all_make_type", "hzd");
            PzGetUtils pzGetUtils = new PzGetUtils();
            pz_nums = pzGetUtils.pzutil(getApplication());

            //活转定
            int f123_l = response.getStringValue(123).length();
            String lv = response.getStringValue(123).substring(55, 63);
            Logger.e(lv + "lv");
            lvs = "";

            if (lv.equals("00000000")) {
                lvs = "0.00000%";
            } else {
                String lv_first = lv.replaceFirst("^0+", "").substring(0, 1);
                int l = lv.replaceFirst("^0+", "").length() - 1;
                String lv_ed = lv.replaceFirst("^0+", "").substring(lv.replaceFirst("^0+", "").length() - l);
                lvs = lv_first + "." + lv_ed + "%";
            }
            final String finalLvs = lvs;
            //戶名
            String names = response.getStringValue(123).substring(71, 131);
            String reg = "[^\u4e00-\u9fa5]";

            name = names.replaceAll(reg, " ").substring(0, 5);
            dqzh = response.getStringValue(123).substring(4, 9);

//余额
            ye = response.getStringValue(123).substring(f123_l - 44, f123_l - 29);
//            //起息日
//            qxr = response.getStringValue(123).substring(64, 71);
//            Logger.e(qxr.length() + "" + qxr);
            //到昔日
            dxr = response.getStringValue(123).substring(63, 71);
            Logger.e("{" + dxr + "}");
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");// HH:mm:ss
                    //获取当前时间
                    Date date = new Date(System.currentTimeMillis());
                    homeCardLayout.setVisibility(View.GONE);
                    liveTransfersSuccessMoney.setText("￥" + inputMoneyEdtext.getText().toString());
                    liveTransfersSuccessUsernum.setText(bindNum);
                    liveTransfersSuccessDealtype.setText(live_to_atfix);
                    if (live_to_atfix.equals("整存整取")) {
                        liveTransfersSuccessTime.setText(save_time);
                    } else {
                        liveTransfersSuccessTime.setText(select_cq + "天");
                    }

                    liveTransfersSuccessLayout.setVisibility(View.VISIBLE);
                    liveTransfersSuccessRateofinterest.setText(finalLvs);
                    liveTransfersSuccessUpdata.setText(simpleDateFormat.format(date).replaceAll("/", ""));
                    liveTransfersSuccessIsunloading.setText(conver_saving);
                }
            });
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");// HH:mm:ss
            //获取当前时间
            Date date = new Date(System.currentTimeMillis());
            Logger.e("Date获取当前日期时间" + simpleDateFormat.format(date).replace("/", ""));
            StatisticalData_bean bean = new StatisticalData_bean(rwNUm, inputMoneyEdtext.getText().toString(), time, "活转定", bindNum, name, SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), String.valueOf(pz_nums));
            String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", ""), "");
            Gson gson = new Gson();
            List<StatisticalData_bean> beans = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
            }.getType());
            beans.add(bean);
            SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", ""), gson.toJson(beans));

            //汇总查询
            String STAT_DATAALL = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", "");
            List<Summary_Bean> beanalls = gson.fromJson(STAT_DATAALL, new TypeToken<List<Summary_Bean>>() {
            }.getType());
            if (!beanalls.get(0).getHzd().equals("")) {
                String data[] = beanalls.get(0).getHzd().split(",");
                int num = Integer.valueOf(data[1]) + 1;
                double money;

                Logger.e(data[0] + "aaaaaaaaaaa" + inputMoneyEdtext.getText().toString());
                if (data[0].contains(".") && inputMoneyEdtext.getText().toString().contains(".")) {
                    money = Double.parseDouble(data[0]) + Double.parseDouble(inputMoneyEdtext.getText().toString());
                } else if (data[0].contains(".") && !inputMoneyEdtext.getText().toString().contains(".")) {
                    money = Double.parseDouble(data[0]) + Integer.parseInt(inputMoneyEdtext.getText().toString());
                } else if (!data[0].contains(".") && inputMoneyEdtext.getText().toString().contains(".")) {
                    money = Integer.valueOf(data[0]) + Double.parseDouble(inputMoneyEdtext.getText().toString());
                } else {
                    money = Integer.valueOf(data[0]) + Integer.valueOf(inputMoneyEdtext.getText().toString());
                }
//                BigDecimal n = new BigDecimal("0");
                String getHzd = money + "," + num;
                Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), beanalls.get(0).getZzhk(), beanalls.get(0).getYdhf(), beanalls.get(0).getLthf(), beanalls.get(0).getSgcc(), beanalls.get(0).getDzh(), getHzd, beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), beanalls.get(0).getHnyqy(), beanalls.get(0).getHnyjy());
                beanalls.clear();
                beanalls.add(summary_bean);
                Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));

            } else {

                int num = 1;
                int money = Integer.valueOf(inputMoneyEdtext.getText().toString());
                String getHzd = money + "," + num;
                Logger.e(getHzd);
                Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), beanalls.get(0).getZzhk(), beanalls.get(0).getYdhf(), beanalls.get(0).getLthf(), beanalls.get(0).getSgcc(), beanalls.get(0).getDzh(), getHzd, beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), beanalls.get(0).getHnyqy(), beanalls.get(0).getHnyjy());
                beanalls.clear();
                beanalls.add(summary_bean);
                Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));

            }

        } else if (op_type.equals("zhcx")) {
            SpUtils.getSPUtil(getApplicationContext()).putString("all_make_type", "zhcx");

            //子账户查询
            if (response.getStringValue(59) == null) {
                f59_dq = false;
            } else {
                if (response.getStringValue(59).substring(0, 1).equals("0")) {
                    f59_dq = true;
                    f59data = "2" + response.getStringValue(59).substring(1, response.getStringValue(59).length());
                } else {
                    f59_dq = false;
                }
            }

            List<Map<String, String>> list = new ArrayList<Map<String, String>>();
            // 子账户信息
            if (response.getField(123) != null) {
                f120type = "0";
                String f123 = response.getStringValue(123);

//			System.out.println("f123=["+f123+"]");
                f123 = f123 + " ";// 防止末尾没有内容导致 split 函数计算不准确
                String notes[] = f123.split("[\u007c]");

                String custname = notes[0]; // 客户名称
                String signflag = notes[1]; // 签约标志
                String prodname = notes[2]; // 理财产品名称
                String snum = notes[3]; // 明细笔数
                int num = Integer.parseInt(snum);
                name = custname;
                System.out.println("客户名称=[" + custname + "]");
                System.out.println("签约标志=[" + signflag + "]");
                System.out.println("理财产品名称=[" + prodname + "]");
//			System.out.println("snum=["+snum+"]");

                unpackF123(4, num, notes, list);

            }
            // 当客户子账户过多时，第123域存放不完时，剩余的部分放在120域下发
            if (response.getField(120) != null) {
                f120type = "1";
                String f120 = response.getStringValue(120);

//			System.out.println("f120=["+f120+"]");
                f120 = f120 + " ";// 防止末尾没有内容导致 split 函数计算不准确
                String notes[] = f120.split("[\u007c]");
                String snum = notes[0]; // 明细笔数
                int num = Integer.parseInt(snum);
                unpackF123(1, num, notes, list);

            }

//		System.out.println("list="+list);
            for (int i = 0; i < list.size(); i++) {
                Map<String, String> data = list.get(i);
                System.out.println("第" + i + "个子账户信息=" + data);
            }


        } else if (op_type.equals("dzh")) {

            Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
            try {
                up_rundataUtils.packRequest("0200", "440000",
                        Select_beans.get(positions).getBalanceofAccount(), "0", run_time, String.valueOf(num), f39);
            } catch (IOException e) {
                e.printStackTrace();
            }


            SpUtils.getSPUtil(getApplicationContext()).putString("all_make_type", "dzh");
            PzGetUtils pzGetUtils = new PzGetUtils();
            pz_nums = pzGetUtils.pzutil(getApplication());


            String f123 = response.getStringValue(123);
            String lxb = "";
            String lxa = "";
            cq = f123.substring(f123.length() - 21, f123.length() - 16).replaceFirst("^0+", "");
            Logger.e(f123.substring(25, 40));
            if (f123.substring(25, 40).equals("000000000000000")) {
                lx = "0";
            } else {

                if (f123.substring(25, 40).replaceFirst("^0+", "").length() == 1) {
                    lxa = "0";

                    lxb = "0" + f123.substring(25, 40).replaceFirst("^0+", "").substring(f123.substring(25, 40).replaceFirst("^0+", "").length() - 1);
                } else {
                    lxb = f123.substring(25, 40).replaceFirst("^0+", "").substring(f123.substring(25, 40).replaceFirst("^0+", "").length() - 2);
                }

                if (lxa == "") {
                    lx = "0" + "." + lxb;
                } else {
                    lx = lxa + "." + lxb;
                }
            }
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    homeCardLayout.setVisibility(View.GONE);
                    switchSuccessUsernum.setText(bindNum);
                    switchSuccessMoney.setText(Select_beans.get(positions).getBalanceofAccount());
                    sureSwitchinfoType.setText("定期转活期");
                    switchSuccessTime.setText(Select_beans.get(positions).getPrdsdep());
                    switchSuccessUpday.setText(Select_beans.get(positions).getValuedate());
                    switchSuccessStopday.setText(Select_beans.get(positions).getDuedate());
                    switchSuccessInterest.setText(Select_beans.get(positions).getTrndintc());
                    switchSuccessDealtype.setText("定期转活期");
                    switchSuccessLayout.setVisibility(View.VISIBLE);
                }
            });
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");// HH:mm:ss
            //获取当前时间
            Date date = new Date(System.currentTimeMillis());
            Logger.e("Date获取当前日期时间" + simpleDateFormat.format(date).replace("/", ""));
            StatisticalData_bean bean = new StatisticalData_bean(rwNUm, Select_beans.get(positions).getBalanceofAccount(), time, "定转活", bindNum, name, SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), String.valueOf(pz_nums));
            String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", ""), "");
            Gson gson = new Gson();
            List<StatisticalData_bean> beanss = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
            }.getType());
            beanss.add(bean);
            SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", ""), gson.toJson(beanss));


            //汇总查询
            String STAT_DATAALL = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", "");
            List<Summary_Bean> beanalls = gson.fromJson(STAT_DATAALL, new TypeToken<List<Summary_Bean>>() {
            }.getType());
            if (!beanalls.get(0).getDzh().equals("")) {
                String data[] = beanalls.get(0).getDzh().split(",");
                int num = Integer.valueOf(data[1]) + 1;
                double money;

//                Logger.e(data[0] + "aaaaaaaaaaa" + beans.get(positions).getBalanceofAccount());
//                if (data[0].contains(".") && inputMoneyEdtext.getText().toString().contains(".")) {
//                    money = Double.parseDouble(data[0]) + Double.parseDouble(inputMoneyEdtext.getText().toString());
//                } else if (data[0].contains(".") && !inputMoneyEdtext.getText().toString().contains(".")) {
//                    money = Double.parseDouble(data[0]) + Integer.parseInt(inputMoneyEdtext.getText().toString());
//                } else if (!data[0].contains(".") && inputMoneyEdtext.getText().toString().contains(".")) {
//                    money = Integer.valueOf(data[0]) + Double.parseDouble(inputMoneyEdtext.getText().toString());
//                } else {
                if (data[0].contains(".")) {
                    money = Double.parseDouble(data[0]) + Integer.valueOf(Select_beans.get(positions).getBalanceofAccount());

                } else {
                    money = Integer.valueOf(data[0]) + Integer.valueOf(Select_beans.get(positions).getBalanceofAccount());
                }
//                }
//                BigDecimal n = new BigDecimal("0");

//                Logger.e(Double.parseDouble(data[0]) + "bbbbbbbbbbbbbb");
                String getDzh = money + "," + num;
                Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), beanalls.get(0).getZzhk(), beanalls.get(0).getYdhf(), beanalls.get(0).getLthf(), beanalls.get(0).getSgcc(), getDzh, beanalls.get(0).getHzd(), beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), beanalls.get(0).getHnyqy(), beanalls.get(0).getHnyjy());
                beanalls.clear();
                beanalls.add(summary_bean);
                Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));

            } else {
                int num = 1;
                int money = Integer.valueOf(Select_beans.get(positions).getBalanceofAccount());
                String getDzh = money + "," + num;
                Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), beanalls.get(0).getZzhk(), beanalls.get(0).getYdhf(), beanalls.get(0).getLthf(), beanalls.get(0).getSgcc(), getDzh, beanalls.get(0).getHzd(), beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), beanalls.get(0).getHnyqy(), beanalls.get(0).getHnyjy());
                beanalls.clear();
                beanalls.add(summary_bean);
                Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));

            }
        } else if (op_type.equals("zdcz")) {
            //自动冲正
            Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
            try {
                up_rundataUtils.packRequest("0420", "440000",
                        "000000000000000", "2", run_time, String.valueOf(num), f39);
            } catch (IOException e) {
                e.printStackTrace();
            }


            SpUtils.getSPUtil(getApplicationContext()).putString("all_make_type", "zdcz");
            Toast.makeText(this, "网络出现问题，已自动冲正", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (handler != null) {
            handler.removeCallbacks(runnable);
        }
    }

    @Override
    public void finish() {
        super.finish();
    }


    /**
     * @param start 从第几个子域开始为记录内容
     * @param num   记录条数
     * @param notes 拆包子域集合
     * @param list  返回的拆包结果
     */
    private void unpackF123(int start, int num, String notes[], List<Map<String, String>> list) {

        // 每一条明细记录有17个子域
        int nrecod = 17;
        Logger.e("lengh1=" + notes.length);
        if (f59num != 0) {
            for (int i = 0; i < num; i++) {

                Map<String, String> data = new HashMap<String, String>();
                String prdcode = notes[start + i * nrecod + 0]; // 产品代码
                Logger.e("prdcode=" + prdcode);
                // 产品名称
                pdpname = notes[start + i * nrecod + 1];
                Logger.e("pdpname=" + pdpname);
                String pdpcode = notes[start + i * nrecod + 2]; // 账户编号
                f122_3 = pdpcode;
                Logger.e("pdpcode=" + pdpcode);
                // 理财帐户笔号
                seqno = notes[start + i * nrecod + 3];
                f122_4 = seqno;
                Logger.e("seqno=" + seqno);
                String acctsts = notes[start + i * nrecod + 4]; // 帐户状态
                Logger.e("acctsts=" + acctsts);
                // 帐户余额
                opacamt = notes[start + i * nrecod + 5];
                Logger.e("opacamt=" + opacamt);
                String acctbal = notes[start + i * nrecod + 6]; // 可用余额
                Logger.e("acctbal=" + acctbal);
                // 起息日期
                valdt = notes[start + i * nrecod + 7];
                Logger.e("valdt=" + valdt);
                // 存期
                depprd = notes[start + i * nrecod + 8];
                Logger.e("depprd=" + depprd);
                // 到期日期
                duedt = notes[start + i * nrecod + 9];
                Logger.e("duedt=" + duedt);
                String mngflg = notes[start + i * nrecod + 10]; // 自动转存标志
                Logger.e("mngflg=" + mngflg);
                String prdsdep = notes[start + i * nrecod + 11]; // 约定存期
                Logger.e("prdsdep=" + prdsdep);
                // 利率
                trndintc = notes[start + i * nrecod + 12];
                Logger.e("trndintc=" + trndintc);
                String drwdt = notes[start + i * nrecod + 13]; // 通知支取日期
                Logger.e("drwdt=" + drwdt);
                String drwdsgn = notes[start + i * nrecod + 14]; // 通知支取设定
                Logger.e("drwdsgn=" + drwdsgn);
                String drwamt = notes[start + i * nrecod + 15]; // 通知支取金额
                Logger.e("drwamt=" + drwamt);
                String curiden = notes[start + i * nrecod + 16]; // 钞汇鉴别
                curiden = curiden.trim();
                Logger.e("curiden=" + curiden);
                Logger.e(trndintc + "trndintc");
                String lv_first = trndintc.substring(2, 3);
                String lv_ed = trndintc.substring(3, trndintc.length());
                String lv = lv_first + "." + lv_ed + "%";
                int monl = opacamt.replaceFirst("^0+", "").length();
                String money = opacamt.replaceFirst("^0+", "").substring(0, monl - 2);
                Logger.e(money + "money");
                Select_subaccount_Bean bean = new
                        Select_subaccount_Bean(pdpname, pdpcode, seqno, money, valdt, duedt, lv, pdpname.substring(0, 3), lv);
                Select_beans.add(bean);
                for (int n = 0; n < Select_beans.size(); n++) {
                    if (Select_beans.get(n).getName().equals("惠农赢1号")) {
                        Select_beans.remove(n);
                    }
                }
            }
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    adapter.addData(Select_beans);
//                    adapter_mx.notifyDataSetChanged();
                }
            });
        } else {
            int w;
            if (f120type == "1") {
                w = 0;
            } else {
                w = 1;
            }
            for (int i = w; i < num; i++) {

                Map<String, String> data = new HashMap<String, String>();
                String prdcode = notes[start + i * nrecod + 0]; // 产品代码
                Logger.e("prdcode=" + prdcode);
                // 产品名称
                pdpname = notes[start + i * nrecod + 1];
                Logger.e("pdpname=" + pdpname);
                String pdpcode = notes[start + i * nrecod + 2]; // 账户编号
                f122_3 = pdpcode;
                Logger.e("pdpcode=" + pdpcode);
                // 理财帐户笔号
                seqno = notes[start + i * nrecod + 3];
                f122_4 = seqno;
                Logger.e("seqno=" + seqno);
                String acctsts = notes[start + i * nrecod + 4]; // 帐户状态
                Logger.e("acctsts=" + acctsts);
                // 帐户余额
                opacamt = notes[start + i * nrecod + 5];
                Logger.e("opacamt=" + opacamt);
                String acctbal = notes[start + i * nrecod + 6]; // 可用余额
                Logger.e("acctbal=" + acctbal);
                // 起息日期
                valdt = notes[start + i * nrecod + 7];
                Logger.e("valdt=" + valdt);
                // 存期
                depprd = notes[start + i * nrecod + 8];
                Logger.e("depprd=" + depprd);
                // 到期日期
                duedt = notes[start + i * nrecod + 9];
                Logger.e("duedt=" + duedt);
                String mngflg = notes[start + i * nrecod + 10]; // 自动转存标志
                Logger.e("mngflg=" + mngflg);
                String prdsdep = notes[start + i * nrecod + 11]; // 约定存期
                Logger.e("prdsdep=" + prdsdep);
                // 利率
                trndintc = notes[start + i * nrecod + 12];
                Logger.e("trndintc=" + trndintc);
                String drwdt = notes[start + i * nrecod + 13]; // 通知支取日期
                Logger.e("drwdt=" + drwdt);
                String drwdsgn = notes[start + i * nrecod + 14]; // 通知支取设定
                Logger.e("drwdsgn=" + drwdsgn);
                String drwamt = notes[start + i * nrecod + 15]; // 通知支取金额
                Logger.e("drwamt=" + drwamt);
                String curiden = notes[start + i * nrecod + 16]; // 钞汇鉴别
                curiden = curiden.trim();
                Logger.e("curiden=" + curiden);
                Logger.e(trndintc + "trndintc");
                String lv_first = trndintc.substring(2, 3);
                String lv_ed = trndintc.substring(3, trndintc.length());
                String lv = lv_first + "." + lv_ed + "%";
                int monl = opacamt.replaceFirst("^0+", "").length();

                String money = opacamt.replaceFirst("^0+", "").substring(0, monl - 2);
                Logger.e(money + "money");
                Select_subaccount_Bean bean = new
                        Select_subaccount_Bean(pdpname, pdpcode, seqno, money, valdt, duedt, lv, pdpname.substring(0, 3), lv);
                Select_beans.add(bean);
                for (int n = 0; n < Select_beans.size(); n++) {
                    if (Select_beans.get(n).getName().equals("惠农赢1号")) {
                        Select_beans.remove(n);
                    }
                }

            }
        }
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (f59num == 0) {

                    initdqrecycler(Select_beans);
                    ficationingLayout.setVisibility(View.GONE);
                    ficationingLayout.setVisibility(View.GONE);
                    homeCardLayout.setVisibility(View.GONE);
                    selectSubaccountLayout.setVisibility(View.VISIBLE);
                }

            }
        });

//        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
//        selectSubaccountRecyclerview.setLayoutManager(linearLayoutManager);
//        Select_subaccount_adapter adapter = new Select_subaccount_adapter(R.layout.select_subaccount_adapter_item_layout, beans, "");
//        selectSubaccountRecyclerview.setAdapter(adapter);
//        runOnUiThread(new Runnable() {
//            @Override
//            public void run() {
//                handler = new Handler();
//                runnable = new Runnable() {
//                    @Override
//                    public void run() {
//                        ficationingLayout.setVisibility(View.GONE);
//                        homeCardLayout.setVisibility(View.GONE);
//                        selectSubaccountLayout.setVisibility(View.VISIBLE);
//                    }
//                };
//                handler.postDelayed(runnable, 1000);
//
//            }
//        });
//


    }

    private void initdqrecycler(final List<Select_subaccount_Bean> select_beans) {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
        selectSubaccountRecyclerview.setLayoutManager(linearLayoutManager);
        adapter = new Select_subaccount_adapter(R.layout.select_subaccount_adapter_item_layout, select_beans, "");
        selectSubaccountRecyclerview.setAdapter(adapter);
        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, final int position) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        dqzh = select_beans.get(position).getNum();
                        qxr1 = select_beans.get(position).getValuedate();
                        dxr1 = select_beans.get(position).getDuedate();
                        positions = position;
                        pleaseInputIccardLayout.setVisibility(View.GONE);

                        selectSubaccountLayout.setVisibility(View.GONE);
                        homeCardLayout.setVisibility(View.VISIBLE);
                        connectedToLayout.setVisibility(View.VISIBLE);
                    }
                });

            }
        });


        adapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
            @Override
            public void onLoadMoreRequested() {
                selectSubaccountRecyclerview.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        /**
                         *  Alltotal是总条数，每次上拉加载10条数据
                         *  每次上拉total可以+10
                         *  Alltotal>total
                         *  可以继续上拉加载
                         *  <=表示数据已经加载完毕
                         */

                        if (f59_dq) {
                            adapter.loadMoreComplete();
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    setOnLoadzzhcxMoreData();
                                }
                            }).start();


                        } else {
                            adapter.loadMoreEnd();
                        }
                    }
                }, 3000);
            }
        });
    }

    private void setOnLoadzzhcxMoreData() {
        f59num = f59num + 1;
        num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
        Logger.e("第一次获取" + num);
        excuteSBA(String.valueOf(num), bindNum);
        SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
        Logger.e("第二次获取" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 1000));
    }
}
